from core.logger import DBLogger
from data.schemas.public.domain import Domain
from data.schemas.public.group import Group

logger = DBLogger(__name__)

from core.database.abc.db_model_dao_abc import DbModelDaoABC


class DomainDao(DbModelDaoABC[Group]):
    def __init__(self):
        DbModelDaoABC.__init__(self, __name__, Group, "public.domains")
        self.attribute(Domain.name, str)

    async def get_by_name(self, name: str) -> Group:
        result = await self._db.select_map(
            f"SELECT * FROM {self._table_name} WHERE Name = '{name}'"
        )
        return self.to_object(result[0])


domainDao = DomainDao()
