"""Teams resource."""

from __future__ import annotations

import builtins

from .._client import AplikuClient
from .._models import Team, TeamCreate, TeamUpdate

_list = builtins.list


class TeamsResource:
    def __init__(self, client: AplikuClient) -> None:
        self._client = client

    def list(self) -> _list[Team]:
        """List all teams."""
        data = self._client.get("/api/team")
        return [Team.model_validate(item) for item in data]

    def get(self, team: str) -> Team:
        """Get a single team by path."""
        data = self._client.get(f"/api/team/{team}/")
        return Team.model_validate(data)

    def create(self, team_path: str, name: str) -> Team:
        """Create a new team."""
        body = TeamCreate(team_path=team_path, name=name)
        data = self._client.post("/api/team/create", json=body.model_dump())
        return Team.model_validate(data)

    def update(self, team: str, **kwargs: object) -> Team:
        """Partially update a team."""
        body = TeamUpdate(**kwargs)  # type: ignore[arg-type]
        data = self._client.patch(f"/api/team/{team}/", json=body.model_dump(exclude_none=True))
        return Team.model_validate(data)

    def delete(self, team: str) -> None:
        """Delete a team."""
        self._client.delete(f"/api/team/{team}/")
