"""Profiles handling for the GL Deep Research Python client.

This module provides the Profiles class for retrieving profile configurations,
including the API and MCP tool config formats associated with a profile.

Authors:
    Sahat Nicholas Simangunsong (sahat.n.simangunsong@gdplabs.id)

References:
    https://gdplabs.gitbook.io/gl-deepresearch/api-contract
"""

import logging
from urllib.parse import urljoin

from gl_odr.base import BaseAPI
from gl_odr.models import ProfileResponse

logger = logging.getLogger(__name__)


class Profiles(BaseAPI):
    """Handles Profiles API operations for the GL Deep Research API."""

    def get(
        self,
        name: str,
        extra_headers: dict[str, str] | None = None,
    ) -> ProfileResponse:
        """Retrieve a profile configuration by name.

        Returns the profile details including the expected api_config and
        mcp_config formats that can be passed when creating a task.

        Args:
            name: Profile name (e.g., "GPTR-QUICK", "GPTR-DEEP")
            extra_headers: Additional headers

        Returns:
            ProfileResponse: Profile details including api_config and mcp_config formats

        Raises:
            ValueError: If name is empty
            httpx.HTTPStatusError: If the API request fails (404 if not found)
        """
        if not name:
            raise ValueError("name cannot be empty")

        logger.debug("Getting profile: %s", name)

        url = urljoin(self._client.base_url, f"v1/profiles/{name}")
        headers = self._prepare_headers(extra_headers)

        response_data = self._make_request("GET", url, headers)
        return ProfileResponse(**response_data)
