"""
Profiles resource.
"""

from __future__ import annotations

from typing import TYPE_CHECKING, Any

if TYPE_CHECKING:
    from ..client.base import BaseClient


class ProfilesResource:
    """Resource for managing profiles."""

    _BASE_PATH = "/v1/profiles"

    def __init__(self, client: "BaseClient") -> None:
        self._client = client

    def list(self) -> dict[str, Any]:
        """List all profiles."""
        return self._client._get(self._BASE_PATH)

    def get(self, profile_id: str) -> dict[str, Any]:
        """Get a profile by ID."""
        return self._client._get(f"{self._BASE_PATH}/{profile_id}")

    def create(
        self, *, name: str, description: str | None = None, color: str | None = None
    ) -> dict[str, Any]:
        """Create a new profile."""
        payload: dict[str, Any] = {"name": name}
        if description:
            payload["description"] = description
        if color:
            payload["color"] = color
        return self._client._post(self._BASE_PATH, data=payload)

    def update(self, profile_id: str, **kwargs: Any) -> dict[str, Any]:
        """Update a profile."""
        return self._client._put(f"{self._BASE_PATH}/{profile_id}", data=kwargs)

    def delete(self, profile_id: str) -> dict[str, Any]:
        """Delete a profile."""
        return self._client._delete(f"{self._BASE_PATH}/{profile_id}")

    # Async
    async def alist(self) -> dict[str, Any]:
        return await self._client._aget(self._BASE_PATH)

    async def aget(self, profile_id: str) -> dict[str, Any]:
        return await self._client._aget(f"{self._BASE_PATH}/{profile_id}")

    async def acreate(self, **kwargs: Any) -> dict[str, Any]:
        return await self._client._apost(self._BASE_PATH, data=kwargs)

    async def aupdate(self, profile_id: str, **kwargs: Any) -> dict[str, Any]:
        return await self._client._aput(f"{self._BASE_PATH}/{profile_id}", data=kwargs)

    async def adelete(self, profile_id: str) -> dict[str, Any]:
        return await self._client._adelete(f"{self._BASE_PATH}/{profile_id}")
