"""Clinic management command/query handlers — Phase 13.3."""
from __future__ import annotations

from uuid import UUID

from sqlalchemy.ext.asyncio import AsyncSession

from app.schemas.clinic_management import (
    ClinicPolicyCreate,
    ClinicServiceCreate,
    OperatingHoursPolicyCreate,
    StaffAssignmentCreate,
)
from app.services.clinic_management import ClinicManagementService
from shared.security import CurrentUser


class ClinicManagementCommands:
    def __init__(self, session: AsyncSession) -> None:
        self.svc = ClinicManagementService(session)

    async def create_service(self, tenant_id: UUID, body: ClinicServiceCreate, *, actor=None):
        return await self.svc.create_service(tenant_id, body, actor=actor)

    async def create_staff(self, tenant_id: UUID, body: StaffAssignmentCreate, *, actor=None):
        return await self.svc.create_staff_assignment(tenant_id, body, actor=actor)

    async def create_policy(self, tenant_id: UUID, body: ClinicPolicyCreate, *, actor=None):
        return await self.svc.create_policy(tenant_id, body, actor=actor)

    async def create_hours(self, tenant_id: UUID, body: OperatingHoursPolicyCreate, *, actor=None):
        return await self.svc.create_operating_hours(tenant_id, body, actor=actor)


class ClinicManagementQueries:
    def __init__(self, session: AsyncSession) -> None:
        self.svc = ClinicManagementService(session)

    async def list_services(
        self, tenant_id: UUID, *, clinic_id: UUID | None = None, offset: int = 0, limit: int = 20
    ):
        return await self.svc.list_services(tenant_id, clinic_id=clinic_id, offset=offset, limit=limit)

    async def list_staff(self, tenant_id: UUID, *, offset: int = 0, limit: int = 20):
        return await self.svc.list_staff(tenant_id, offset=offset, limit=limit)

    async def list_policies(self, tenant_id: UUID, *, offset: int = 0, limit: int = 20):
        return await self.svc.list_policies(tenant_id, offset=offset, limit=limit)

    async def list_hours(self, tenant_id: UUID, *, offset: int = 0, limit: int = 20):
        return await self.svc.list_operating_hours(tenant_id, offset=offset, limit=limit)
