from __future__ import annotations

from typing import TYPE_CHECKING


from fortytwo.parameter import Parameter, with_pagination
from fortytwo.resources.campus.parameter import CampusParameters
from fortytwo.resources.campus.resource import GetCampusById, GetCampuses


if TYPE_CHECKING:
    from fortytwo.core import ApiListResponse, ApiResponse, AsyncClient
    from fortytwo.resources.campus.campus import Campus


class AsyncCampusManager:
    """
    Asynchronous manager for campus-related API operations.
    """

    parameters = CampusParameters

    def __init__(self, client: AsyncClient) -> None:
        self.__client = client

    async def get_by_id(self, campus_id: int, *params: Parameter) -> ApiResponse[Campus]:
        """
        Get a campus by ID.

        Args:
            campus_id: The campus ID to fetch
            *params: Additional request parameters

        Returns:
            Campus object

        Raises:
            FortyTwoNotFoundException: If campus is not found
            FortyTwoRequestException: If the request fails
        """
        return await self.__client.request(GetCampusById(campus_id), *params)

    @with_pagination
    async def get_all(
        self,
        *params: Parameter,
        page: int | None = None,
        page_size: int | None = None,
    ) -> ApiListResponse[Campus]:
        """
        Get all campuses.

        Args:
            *params: Additional request parameters
            page: Page number to fetch (1-indexed)
            page_size: Number of items per page (1-100)

        Returns:
            List of Campus objects

        Raises:
            FortyTwoRequestException: If the request fails
        """
        return await self.__client.request(GetCampuses(), *params)
