from fastapi import status
from fastapi.testclient import TestClient


class TestClientTenantGet:
    PATH = "/v1/client-tenants"

    def test_returns_client_tenants_with_active_status(
        self,
        test_client: TestClient,
        registered_identifiers: dict[str, str],
        header_names: dict[str, str],
    ) -> None:
        """ClientTenant一覧を取得できることを確認。"""
        headers = {
            header_names["api_key"]: registered_identifiers["api_key_gen_ai_profile"],
        }

        response = test_client.get(url=self.PATH, headers=headers)

        assert response.status_code == status.HTTP_200_OK
        assert response.json()["tenants"] == [
            {
                "name": registered_identifiers["tenant_gen_ai_profile_2"],
                "status": "active",
            },
            {
                "name": registered_identifiers["tenant_gen_ai_profile_3"],
                "status": "active",
            },
            {
                "name": registered_identifiers["tenant_gen_ai_profile_4"],
                "status": "pending",
            },
        ]

    def test_excludes_client_tenants_of_other_clients(
        self,
        test_client: TestClient,
        registered_identifiers: dict[str, str],
        header_names: dict[str, str],
    ) -> None:
        """他Clientに紐づくClientTenantが一覧に含まれないことを確認。"""
        headers = {
            header_names["api_key"]: registered_identifiers["api_key_hci"],
        }

        response = test_client.get(url=self.PATH, headers=headers)

        assert response.status_code == status.HTTP_200_OK
        assert response.json()["tenants"] == [
            {
                "name": registered_identifiers["tenant_hci_1"],
                "status": "active",
            },
            {
                "name": registered_identifiers["tenant_hci_2"],
                "status": "active",
            },
        ]

    def test_returns_empty_list_when_client_tenant_does_not_exist(
        self,
        test_client: TestClient,
        registered_identifiers: dict[str, str],
        header_names: dict[str, str],
    ) -> None:
        """ClientTenantが一件も存在しない場合、空のリストを取得できることを確認。"""
        headers = {
            header_names["api_key"]: registered_identifiers["api_key_companyme"],
        }

        response = test_client.get(url=self.PATH, headers=headers)

        assert response.status_code == status.HTTP_200_OK
        assert response.json()["tenants"] == []
