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 UserSpace(DbModelABC):
    def __init__(
        self,
        id: SerialId,
        name: str,
        owner_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._name = name
        self._owner_id = owner_id

    @property
    def name(self) -> str:
        return self._name

    @name.setter
    def name(self, value: str):
        self._name = value

    @property
    def owner_id(self) -> SerialId:
        return self._owner_id

    @owner_id.setter
    def owner_id(self, value: SerialId):
        self._owner_id = value

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

        return await userDao.get_by_id(self._owner_id)
