"""Tests for ConditionCodeValidator."""

from __future__ import annotations

from claim_validator.models.institutional import InstitutionalClaimData
from claim_validator.validators.institutional.condition_code import (
    ConditionCodeValidator,
)


class TestConditionCodeValidator:
    def setup_method(self) -> None:
        self.v = ConditionCodeValidator()

    def test_valid_condition_codes(self) -> None:
        claim = InstitutionalClaimData(condition_codes=["01", "07", "A3", "W2"])
        result = self.v.validate(claim)
        assert len(result.findings) == 0

    def test_empty_list_skips(self) -> None:
        claim = InstitutionalClaimData(condition_codes=[])
        result = self.v.validate(claim)
        assert len(result.findings) == 0

    def test_invalid_format(self) -> None:
        claim = InstitutionalClaimData(condition_codes=["1", "ABC", "0!"])
        result = self.v.validate(claim)
        assert len(result.findings) == 3
        assert all(f.code == "INST_INVALID_CONDITION_CODE" for f in result.findings)

    def test_unknown_condition_code(self) -> None:
        claim = InstitutionalClaimData(condition_codes=["Z9"])
        result = self.v.validate(claim)
        assert len(result.findings) == 1
        assert result.findings[0].code == "INST_UNKNOWN_CONDITION_CODE"
        assert result.findings[0].severity.value == "warning"

    def test_mixed_valid_invalid_unknown(self) -> None:
        claim = InstitutionalClaimData(condition_codes=["01", "!!!", "Z9"])
        result = self.v.validate(claim)
        codes = [f.code for f in result.findings]
        assert "INST_INVALID_CONDITION_CODE" in codes
        assert "INST_UNKNOWN_CONDITION_CODE" in codes
        assert len(result.findings) == 2  # no finding for valid "01"
