from datetime import datetime
from typing import Optional

from async_property import async_property

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


class RoleUser(DbJoinModelABC):
    def __init__(
        self,
        id: SerialId,
        role_id: SerialId,
        user_id: SerialId,
        deleted: bool = False,
        editor_id: Optional[SerialId] = None,
        created: Optional[datetime] = None,
        updated: Optional[datetime] = None,
    ):
        DbJoinModelABC.__init__(
            self, id, role_id, user_id, deleted, editor_id, created, updated
        )
        self._role_id = role_id
        self._user_id = user_id

    @property
    def role_id(self) -> int:
        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)

    @property
    def user_id(self) -> int:
        return self._user_id

    @async_property
    async def user(self):
        from data.schemas.administration.user_dao import userDao

        return await userDao.get_by_id(self._user_id)
