# Standard library imports

# PyQt imports

# Third party imports
from alchemical import Alchemical  # type:ignore

# App imports


class DatabaseManager:
    """
    Singleton class to ensure we only ever have one db object
    """

    __instance = None

    def __init__(self, database_url: str, **kwargs: dict) -> None:
        if DatabaseManager.__instance is None:
            self.db = Alchemical(database_url, **kwargs)
            # Database managed by Alembic so no create_all() required
            # self.db.create_all()
            DatabaseManager.__instance = self
        else:
            raise Exception("Attempted to create a second DatabaseManager instance")

    @staticmethod
    def get_instance(database_url: str, **kwargs: dict) -> Alchemical:
        if DatabaseManager.__instance is None:
            DatabaseManager(database_url, **kwargs)
        return DatabaseManager.__instance
