from datetime import datetime
from typing import Optional

from async_property import async_property

from core.database.abc.db_model_abc import DbModelABC
from core.typing import SerialId


class GroupRoleAssignment(DbModelABC):
    def __init__(
        self,
        id: SerialId,
        group_id: SerialId,
        role_id: SerialId,
        deleted: bool = False,
        editor_id: Optional[SerialId] = None,
        created: Optional[datetime] = None,
        updated: Optional[datetime] = None,
    ):
        DbModelABC.__init__(self, id, deleted, editor_id, created, updated)
        self._group_id = group_id
        self._role_id = role_id

    @property
    def group_id(self) -> SerialId:
        return self._group_id

    @async_property
    async def group(self):
        from data.schemas.public.group_dao import groupDao

        return await groupDao.get_by_id(self._group_id)

    @property
    def role_id(self) -> SerialId:
        return self._role_id

    @async_property
    async def role(self):
        from data.schemas.permission.role_dao import roleDao

        return await roleDao.get_by_id(self._role_id)
