from abc import abstractmethod
from datetime import datetime
from typing import Type

from core.database.abc.data_access_object_abc import DataAccessObjectABC
from core.database.abc.db_model_abc import DbModelABC


class DbModelDaoABC[T_DBM](DataAccessObjectABC[T_DBM]):

    @abstractmethod
    def __init__(self, source: str, model_type: Type[T_DBM], table_name: str):
        DataAccessObjectABC.__init__(self, source, model_type, table_name)

        self.attribute(DbModelABC.id, int, ignore=True)
        self.attribute(DbModelABC.deleted, bool)
        self.attribute(DbModelABC.editor_id, int, ignore=True)  # handled by db trigger

        self.reference(
            "editor", "id", DbModelABC.editor_id, "administration.users"
        )  # not relevant for updates due to editor_id

        self.attribute(
            DbModelABC.created, datetime, ignore=True
        )  # handled by db trigger
        self.attribute(
            DbModelABC.updated, datetime, ignore=True
        )  # handled by db trigger
