"""Tests for TeamsResource."""

from __future__ import annotations

import httpx
import pytest

from appliku import Appliku


@pytest.fixture()
def teams_data() -> dict[str, object]:
    return {
        "id": 1,
        "team_path": "acme",
        "name": "Acme Inc",
        "plan": "pro",
        "aws_credentials_set": False,
        "do_token_set": False,
    }


class TestTeamsList:
    def test_list_returns_teams(
        self,
        mock_client: tuple[Appliku, list[httpx.Response]],
        teams_data: dict[str, object],
    ) -> None:
        client, responses = mock_client
        responses.append(httpx.Response(200, json=[teams_data]))
        result = client.teams.list()
        assert len(result) == 1
        assert result[0].name == "Acme Inc"
        assert result[0].team_path == "acme"


class TestTeamsGet:
    def test_get_returns_team(
        self, mock_client: tuple[Appliku, list[httpx.Response]], teams_data: dict[str, object]
    ) -> None:
        client, responses = mock_client
        responses.append(httpx.Response(200, json=teams_data))
        team = client.teams.get("acme")
        assert team.id == 1
        assert team.name == "Acme Inc"


class TestTeamsCreate:
    def test_create_returns_team(
        self, mock_client: tuple[Appliku, list[httpx.Response]], teams_data: dict[str, object]
    ) -> None:
        client, responses = mock_client
        responses.append(httpx.Response(201, json=teams_data))
        team = client.teams.create("acme", "Acme Inc")
        assert team.name == "Acme Inc"


class TestTeamsUpdate:
    def test_update_returns_team(self, mock_client: tuple[Appliku, list[httpx.Response]]) -> None:
        client, responses = mock_client
        updated = {"id": 1, "team_path": "acme", "name": "Acme Corp"}
        responses.append(httpx.Response(200, json=updated))
        team = client.teams.update("acme", name="Acme Corp")
        assert team.name == "Acme Corp"


class TestTeamsDelete:
    def test_delete_succeeds(self, mock_client: tuple[Appliku, list[httpx.Response]]) -> None:
        client, responses = mock_client
        responses.append(httpx.Response(204))
        client.teams.delete("acme")  # should not raise
