"""Template query handlers — Phase 11.4."""
from __future__ import annotations

from uuid import UUID

from sqlalchemy.ext.asyncio import AsyncSession

from app.services.templates import ExperienceTemplateService
from app.specifications.templates import (
    InstantiationListSpec,
    TemplateListSpec,
    TemplateVersionListSpec,
)


class TemplateQueries:
    def __init__(self, session: AsyncSession) -> None:
        self.service = ExperienceTemplateService(session)

    async def get_template(self, tenant_id: UUID, template_id: UUID):
        return await self.service.get_template(tenant_id, template_id)

    async def list_templates(
        self,
        tenant_id: UUID,
        *,
        offset: int,
        limit: int,
        spec: TemplateListSpec | None,
    ):
        return await self.service.list_templates(
            tenant_id, offset=offset, limit=limit, spec=spec
        )

    async def get_version(self, tenant_id: UUID, version_id: UUID):
        return await self.service.get_version(tenant_id, version_id)

    async def list_versions(
        self,
        tenant_id: UUID,
        *,
        offset: int,
        limit: int,
        spec: TemplateVersionListSpec | None,
    ):
        return await self.service.list_versions(
            tenant_id, offset=offset, limit=limit, spec=spec
        )

    async def get_instantiation(self, tenant_id: UUID, instantiation_id: UUID):
        return await self.service.get_instantiation(tenant_id, instantiation_id)

    async def list_instantiations(
        self,
        tenant_id: UUID,
        *,
        offset: int,
        limit: int,
        spec: InstantiationListSpec | None,
    ):
        return await self.service.list_instantiations(
            tenant_id, offset=offset, limit=limit, spec=spec
        )
