from api_graphql.abc.db_model_query_abc import DbModelQueryABC
from data.schemas.public.domain import Domain
from data.schemas.public.domain_dao import domainDao
from data.schemas.public.group import Group
from data.schemas.public.short_url import ShortUrl
from data.schemas.public.short_url_dao import shortUrlDao


class DomainQuery(DbModelQueryABC):
    def __init__(self):
        DbModelQueryABC.__init__(self, "Domain", domainDao, with_history=True)

        self.set_field("name", lambda x, *_: x.name)
        self.set_field("shortUrls", self._get_urls)

        self.set_history_reference_dao(shortUrlDao, "domainid")

    @staticmethod
    async def _get_urls(domain: Domain, *_):
        return await shortUrlDao.find_by({ShortUrl.domain_id: domain.id})
