"""Tests for TaxonomyValidator."""

from __future__ import annotations

from claim_validator.constants import Severity
from claim_validator.models.results import ValidatorOutput
from claim_validator.validators.rule_based.taxonomy import TaxonomyValidator

from tests.conftest import build_claim_unchecked


def _base_claim(**overrides) -> dict:
    """Minimal claim dict for taxonomy testing."""
    data: dict = {
        "billing_provider_npi": "1234567893",
        "subscriber_id": "XYZ123456",
        "diagnosis_codes": [{"code": "J06.9", "pointer": 1}],
        "lines": [
            {
                "procedure_code": "99213",
                "diagnosis_pointers": [1],
                "charge_amount": 150.00,
            },
        ],
    }
    data.update(overrides)
    return data


class TestTaxonomyValidator:
    """Tests for billing provider taxonomy validation."""

    def setup_method(self) -> None:
        self.validator = TaxonomyValidator()

    def test_valid_taxonomy_no_findings(self) -> None:
        claim = build_claim_unchecked(
            **_base_claim(billing_provider_taxonomy="207Q00000X"),
        )
        result = self.validator.validate(claim)
        assert isinstance(result, ValidatorOutput)
        assert result.findings == []

    def test_invalid_taxonomy_produces_warning(self) -> None:
        claim = build_claim_unchecked(
            **_base_claim(billing_provider_taxonomy="000INVALID"),
        )
        result = self.validator.validate(claim)
        findings = [f for f in result.findings if f.code == "INVALID_TAXONOMY_CODE"]
        assert len(findings) == 1
        assert findings[0].severity == Severity.WARNING
        assert findings[0].field_name == "billing_provider_taxonomy"

    def test_none_taxonomy_skipped(self) -> None:
        claim = build_claim_unchecked(
            **_base_claim(billing_provider_taxonomy=None),
        )
        result = self.validator.validate(claim)
        assert result.findings == []

    def test_empty_taxonomy_skipped(self) -> None:
        claim = build_claim_unchecked(
            **_base_claim(billing_provider_taxonomy=""),
        )
        result = self.validator.validate(claim)
        assert result.findings == []

    def test_whitespace_taxonomy_skipped(self) -> None:
        claim = build_claim_unchecked(
            **_base_claim(billing_provider_taxonomy="   "),
        )
        result = self.validator.validate(claim)
        assert result.findings == []
