"""Theme & layout query handlers — Phase 11.3 (versioned)."""
from __future__ import annotations

from uuid import UUID

from sqlalchemy.ext.asyncio import AsyncSession

from app.services.themes import ExperienceThemeService
from app.specifications.themes import (
    LayoutListSpec,
    LayoutVersionListSpec,
    PageLayoutBindingListSpec,
    SiteThemeBindingListSpec,
    ThemeListSpec,
    ThemeVersionListSpec,
)


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

    # --- Themes ---

    async def get_theme(self, tenant_id: UUID, theme_id: UUID):
        return await self.service.get_theme(tenant_id, theme_id)

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

    # --- Theme Versions ---

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

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

    # --- Layouts ---

    async def get_layout(self, tenant_id: UUID, layout_id: UUID):
        return await self.service.get_layout(tenant_id, layout_id)

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

    # --- Layout Versions ---

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

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

    # --- Site Theme Bindings ---

    async def get_site_theme_binding(self, tenant_id: UUID, binding_id: UUID):
        return await self.service.get_site_theme_binding(tenant_id, binding_id)

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

    # --- Page Layout Bindings ---

    async def get_page_layout_binding(self, tenant_id: UUID, binding_id: UUID):
        return await self.service.get_page_layout_binding(tenant_id, binding_id)

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