from core.logger import DBLogger
from data.schemas.public.group_role_assignment import GroupRoleAssignment

logger = DBLogger(__name__)

from core.database.abc.db_model_dao_abc import DbModelDaoABC


class GroupRoleAssignmentDao(DbModelDaoABC[GroupRoleAssignment]):
    def __init__(self):
        DbModelDaoABC.__init__(
            self, __name__, GroupRoleAssignment, "public.group_role_assignments"
        )

        self.attribute(GroupRoleAssignment.group_id, int)
        self.attribute(GroupRoleAssignment.role_id, int)

    async def get_by_group_id(
        self, gid: int, with_deleted=False
    ) -> list[GroupRoleAssignment]:
        f = [{GroupRoleAssignment.group_id: gid}]
        if not with_deleted:
            f.append({GroupRoleAssignment.deleted: False})

        return await self.find_by(f)

    async def get_by_role_id(
        self, rid: int, with_deleted=False
    ) -> list[GroupRoleAssignment]:
        f = [{GroupRoleAssignment.role_id: rid}]
        if not with_deleted:
            f.append({GroupRoleAssignment.deleted: False})

        return await self.find_by(f)


groupRoleAssignmentDao = GroupRoleAssignmentDao()
