"""Coach & Staff repositories — Phase 9.3."""
from __future__ import annotations

from uuid import UUID

from sqlalchemy import select

from app.models.staff import (
    StaffAssignment,
    StaffAvailability,
    StaffCertificate,
    StaffSkill,
    StaffWorkingHours,
)
from app.repositories.base import TenantBaseRepository


class StaffCertificateRepository(TenantBaseRepository[StaffCertificate]):
    model = StaffCertificate

    async def list_by_coach(self, tenant_id: UUID, coach_id: UUID, *, offset: int = 0, limit: int = 20):
        stmt = (
            select(self.model)
            .where(
                self.model.tenant_id == tenant_id,
                self.model.coach_id == coach_id,
                self.model.is_deleted.is_(False),
            )
            .offset(offset)
            .limit(limit)
        )
        result = await self.session.execute(stmt)
        return result.scalars().all()


class StaffSkillRepository(TenantBaseRepository[StaffSkill]):
    model = StaffSkill

    async def list_by_coach(self, tenant_id: UUID, coach_id: UUID, *, offset: int = 0, limit: int = 20):
        stmt = (
            select(self.model)
            .where(
                self.model.tenant_id == tenant_id,
                self.model.coach_id == coach_id,
                self.model.is_deleted.is_(False),
            )
            .offset(offset)
            .limit(limit)
        )
        result = await self.session.execute(stmt)
        return result.scalars().all()


class StaffWorkingHoursRepository(TenantBaseRepository[StaffWorkingHours]):
    model = StaffWorkingHours

    async def list_by_coach(self, tenant_id: UUID, coach_id: UUID, *, offset: int = 0, limit: int = 20):
        stmt = (
            select(self.model)
            .where(
                self.model.tenant_id == tenant_id,
                self.model.coach_id == coach_id,
                self.model.is_deleted.is_(False),
            )
            .offset(offset)
            .limit(limit)
        )
        result = await self.session.execute(stmt)
        return result.scalars().all()


class StaffAvailabilityRepository(TenantBaseRepository[StaffAvailability]):
    model = StaffAvailability

    async def list_by_coach(self, tenant_id: UUID, coach_id: UUID, *, offset: int = 0, limit: int = 20):
        stmt = (
            select(self.model)
            .where(
                self.model.tenant_id == tenant_id,
                self.model.coach_id == coach_id,
                self.model.is_deleted.is_(False),
            )
            .offset(offset)
            .limit(limit)
        )
        result = await self.session.execute(stmt)
        return result.scalars().all()


class StaffAssignmentRepository(TenantBaseRepository[StaffAssignment]):
    model = StaffAssignment

    async def list_by_coach(self, tenant_id: UUID, coach_id: UUID, *, offset: int = 0, limit: int = 20):
        stmt = (
            select(self.model)
            .where(
                self.model.tenant_id == tenant_id,
                self.model.coach_id == coach_id,
                self.model.is_deleted.is_(False),
            )
            .offset(offset)
            .limit(limit)
        )
        result = await self.session.execute(stmt)
        return result.scalars().all()
