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 UserInvitation(DbModelABC):
    def __init__(
        self,
        id: SerialId,
        email: str,
        invitation: str,
        user_space_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._email = email
        self._user_space_id = user_space_id
        self._invitation = invitation

    @property
    def email(self) -> str:
        return self._email

    @email.setter
    def email(self, value: str):
        self._email = value

    @property
    def invitation(self) -> Optional[str]:
        return self._invitation

    @invitation.setter
    def invitation(self, value: Optional[str]):
        self._invitation = value

    @property
    def user_space_id(self) -> SerialId:
        return self._user_space_id

    @async_property
    async def user_space(self):
        from data.schemas.public.user_space_dao import userSpaceDao

        return await userSpaceDao.get_by_id(self._user_space_id)
