from __future__ import annotations

from sqlalchemy.orm import Session

from app.core.logging import get_logger
from app.schemas.employee import EmployeeRead
from app.services.employee import EmployeeService
from app.services.pagination import PageResult

logger = get_logger("app.services.employee")


class EmployeePaginationService:
    def __init__(self, db: Session, *, tenant_id: str) -> None:
        self.service = EmployeeService(db, tenant_id=tenant_id)

    def list_employees_page(
        self,
        *,
        status: str | None = None,
        keyword: str | None = None,
        page: int | None,
        page_size: int | None,
    ) -> PageResult[EmployeeRead]:
        self.service.ensure_directory_ready()
        result = self.service.repository.list_page(
            status=status,
            keyword=keyword,
            page=page,
            page_size=page_size,
        )
        logger.info(
            "Listed employees page (count=%d, total=%d, page=%d, page_size=%d)",
            len(result.items),
            result.total,
            result.page,
            result.page_size,
        )
        return result.map(self.service._serialize_employee)
