"""Tests for InvitesResource."""

from __future__ import annotations

import httpx
import pytest

from appliku import Appliku


@pytest.fixture()
def invite_data() -> dict[str, object]:
    return {
        "id": 1,
        "email": "invite@example.com",
        "role": "member",
        "status": "pending",
        "created_at": "2024-01-01T00:00:00Z",
    }


class TestInvitesList:
    def test_list_returns_paginated(
        self,
        mock_client: tuple[Appliku, list[httpx.Response]],
        invite_data: dict[str, object],
        paginated_response: object,
    ) -> None:
        client, responses = mock_client
        responses.append(httpx.Response(200, json=paginated_response([invite_data])))  # type: ignore[operator]
        result = client.invites.list("acme")
        assert result.count == 1
        assert result.results[0].email == "invite@example.com"


class TestInvitesCreate:
    def test_create_returns_invite(
        self, mock_client: tuple[Appliku, list[httpx.Response]], invite_data: dict[str, object]
    ) -> None:
        client, responses = mock_client
        responses.append(httpx.Response(201, json=invite_data))
        invite = client.invites.create("acme", "invite@example.com", "member")
        assert invite.role == "member"


class TestInvitesDelete:
    def test_delete_succeeds(self, mock_client: tuple[Appliku, list[httpx.Response]]) -> None:
        client, responses = mock_client
        responses.append(httpx.Response(204))
        client.invites.delete("acme", 1)


class TestInvitesAcceptDecline:
    def test_accept(self, mock_client: tuple[Appliku, list[httpx.Response]]) -> None:
        client, responses = mock_client
        responses.append(httpx.Response(200, json={"status": "accepted"}))
        result = client.invites.accept("acme", 1, "tok_abc")
        assert result["status"] == "accepted"

    def test_decline(self, mock_client: tuple[Appliku, list[httpx.Response]]) -> None:
        client, responses = mock_client
        responses.append(httpx.Response(200, json={"status": "declined"}))
        result = client.invites.decline("acme", 1, "tok_abc")
        assert result["status"] == "declined"
