from fastapi import status
from fastapi.testclient import TestClient


class TestQuotaCheckHead:
    PATH = "/v1/quota/check"

    def test_quota_available_for_alpha_1(
        self,
        test_client: TestClient,
        registered_identifiers: dict[str, str],
        header_names: dict[str, str],
    ) -> None:
        headers = {
            header_names["api_key"]: registered_identifiers["api_key_gen_ai_profile"],
            header_names["tenant_name"]: registered_identifiers["tenant_alpha_1"],
        }
        response = test_client.head(url=self.PATH, headers=headers)
        assert response.status_code == status.HTTP_200_OK

    def test_quota_available_for_alpha_2(
        self,
        test_client: TestClient,
        registered_identifiers: dict[str, str],
        header_names: dict[str, str],
    ) -> None:
        headers = {
            header_names["api_key"]: registered_identifiers["api_key_gen_ai_profile"],
            header_names["tenant_name"]: registered_identifiers["tenant_alpha_2"],
        }
        response = test_client.head(url=self.PATH, headers=headers)
        assert response.status_code == status.HTTP_200_OK

    def test_quota_available_for_another_valid_client_api_key(
        self,
        test_client: TestClient,
        registered_identifiers: dict[str, str],
        header_names: dict[str, str],
    ) -> None:
        headers = {
            header_names["api_key"]: registered_identifiers["api_key_hci"],
            header_names["tenant_name"]: registered_identifiers["tenant_alpha_1"],
        }
        response = test_client.head(url=self.PATH, headers=headers)
        assert response.status_code == status.HTTP_200_OK

    def test_api_key_missing(self, test_client: TestClient) -> None:
        response = test_client.head(url=self.PATH)
        assert response.status_code == status.HTTP_401_UNAUTHORIZED

    def test_api_key_empty(
        self,
        test_client: TestClient,
        registered_identifiers: dict[str, str],
        header_names: dict[str, str],
    ) -> None:
        headers = {
            header_names["api_key"]: "",
            header_names["tenant_name"]: registered_identifiers["tenant_alpha_1"],
        }
        response = test_client.head(url=self.PATH, headers=headers)
        assert response.status_code == status.HTTP_401_UNAUTHORIZED

    def test_api_key_invalid(
        self,
        test_client: TestClient,
        registered_identifiers: dict[str, str],
        header_names: dict[str, str],
    ) -> None:
        headers = {
            header_names["api_key"]: "invalid_api_key",
            header_names["tenant_name"]: registered_identifiers["tenant_alpha_1"],
        }
        response = test_client.head(url=self.PATH, headers=headers)
        assert response.status_code == status.HTTP_401_UNAUTHORIZED

    def test_api_key_invalid_secret(
        self,
        test_client: TestClient,
        registered_identifiers: dict[str, str],
        header_names: dict[str, str],
    ) -> None:
        headers = {
            header_names["api_key"]: "test.gen_ai_profile.test.46b7e57d4185a394eb5a90ea.invalid-secret",
            header_names["tenant_name"]: registered_identifiers["tenant_alpha_1"],
        }
        response = test_client.head(url=self.PATH, headers=headers)
        assert response.status_code == status.HTTP_401_UNAUTHORIZED

    def test_api_key_invalid_format(
        self,
        test_client: TestClient,
        registered_identifiers: dict[str, str],
        header_names: dict[str, str],
    ) -> None:
        headers = {
            header_names["api_key"]: "test.gen_ai_profile.test",
            header_names["tenant_name"]: registered_identifiers["tenant_alpha_1"],
        }
        response = test_client.head(url=self.PATH, headers=headers)
        assert response.status_code == status.HTTP_401_UNAUTHORIZED

    def test_tenant_name_missing(
        self,
        test_client: TestClient,
        registered_identifiers: dict[str, str],
        header_names: dict[str, str],
    ) -> None:
        headers = {header_names["api_key"]: registered_identifiers["api_key_gen_ai_profile"]}
        response = test_client.head(url=self.PATH, headers=headers)
        assert response.status_code == status.HTTP_422_UNPROCESSABLE_CONTENT

    def test_tenant_name_empty(
        self,
        test_client: TestClient,
        registered_identifiers: dict[str, str],
        header_names: dict[str, str],
    ) -> None:
        headers = {
            header_names["api_key"]: registered_identifiers["api_key_gen_ai_profile"],
            header_names["tenant_name"]: "",
        }
        response = test_client.head(url=self.PATH, headers=headers)
        assert response.status_code == status.HTTP_404_NOT_FOUND

    def test_quota_exceeded(
        self,
        test_client: TestClient,
        registered_identifiers: dict[str, str],
        header_names: dict[str, str],
    ) -> None:
        headers = {
            header_names["api_key"]: registered_identifiers["api_key_gen_ai_profile"],
            header_names["tenant_name"]: registered_identifiers["tenant_beta_1"],
        }
        response = test_client.head(url=self.PATH, headers=headers)
        assert response.status_code == status.HTTP_402_PAYMENT_REQUIRED

    def test_tenant_not_found(
        self,
        test_client: TestClient,
        registered_identifiers: dict[str, str],
        header_names: dict[str, str],
    ) -> None:
        headers = {
            header_names["api_key"]: registered_identifiers["api_key_gen_ai_profile"],
            header_names["tenant_name"]: "invalid_tenant_name",
        }
        response = test_client.head(url=self.PATH, headers=headers)
        assert response.status_code == status.HTTP_404_NOT_FOUND
