from __future__ import annotations

from abc import ABC, abstractmethod
from pathlib import Path
from typing import Optional

from graph.connections.db_connection import DbConnection


class DbInstance(ABC):
    def __enter__(self) -> DbInstance:
        self.open()
        return self

    def __exit__(self, exception_type, exception_value, exception_traceback) -> None:
        self.close()

    @abstractmethod
    def open(self) -> None:
        pass

    @abstractmethod
    def close(self) -> None:
        pass

    @abstractmethod
    def get_db_path(self) -> Path:
        pass

    @abstractmethod
    def exists(self) -> bool:
        pass

    @abstractmethod
    def get_new_conn(self, timeout_seconds: Optional[int] = None) -> DbConnection:
        pass
