"""Dispatch query handlers — Phase 10.5."""
from __future__ import annotations

from uuid import UUID

from sqlalchemy.ext.asyncio import AsyncSession

from app.services.dispatch import DispatchJobService, JobAssignmentService
from app.specifications.dispatch import DispatchJobListSpec, JobAssignmentListSpec


class DispatchQueries:
    def __init__(self, session: AsyncSession) -> None:
        self.jobs = DispatchJobService(session)
        self.assignments = JobAssignmentService(session)

    async def get_job(self, tenant_id: UUID, job_id: UUID):
        return await self.jobs.get(tenant_id, job_id)

    async def list_jobs(
        self, tenant_id: UUID, *, offset: int, limit: int, spec: DispatchJobListSpec | None
    ):
        return await self.jobs.list(tenant_id, offset=offset, limit=limit, spec=spec)

    async def get_assignment(self, tenant_id: UUID, assignment_id: UUID):
        return await self.assignments.get(tenant_id, assignment_id)

    async def list_assignments(
        self,
        tenant_id: UUID,
        *,
        offset: int,
        limit: int,
        spec: JobAssignmentListSpec | None,
    ):
        return await self.assignments.list(
            tenant_id, offset=offset, limit=limit, spec=spec
        )
