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
from data.schemas.public.short_url import ShortUrl
from data.schemas.public.short_url_dao import shortUrlDao


class ShortUrlVisit(DbModelABC):
    def __init__(
        self,
        id: SerialId,
        short_url_id: SerialId,
        client: Optional[str],
        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._short_url_id = short_url_id
        self._client = client

    @property
    def short_url_id(self) -> SerialId:
        return self._short_url_id

    @async_property
    async def short_url(self) -> ShortUrl:
        return await shortUrlDao.get_by_id(self._short_url_id)

    @property
    def client(self) -> Optional[str]:
        return self._client
