"""Tests for the expanded timely filing payer table."""

from __future__ import annotations

import json
from importlib.resources import files

from claim_validator.shared.code_tables.timely_filing import get_filing_deadline


class TestExpandedTimelyFiling:
    """Verify the expanded timely filing table."""

    def test_medicare_deadline(self) -> None:
        assert get_filing_deadline("MEDICARE") == 365

    def test_cigna_short_deadline(self) -> None:
        assert get_filing_deadline("CIGNA002") == 90

    def test_workers_comp(self) -> None:
        assert get_filing_deadline("WORKERS_COMP") == 90

    def test_aetna_better(self) -> None:
        assert get_filing_deadline("AETNA_BETTER") == 365

    def test_bluecross_fl(self) -> None:
        assert get_filing_deadline("BLUECROSS_FL") == 180

    def test_expanded_table_has_50_plus(self) -> None:
        data_pkg = files("claim_validator.shared.data")
        text = data_pkg.joinpath("timely_filing.json").read_text(encoding="utf-8")
        table = json.loads(text)
        # Exclude _default from the count
        payer_count = sum(1 for k in table if not k.startswith("_"))
        assert payer_count >= 50

    def test_case_insensitive_lookup(self) -> None:
        assert get_filing_deadline("medicare") == 365
        assert get_filing_deadline("  CIGNA002  ") == 90

    def test_original_payers_preserved(self) -> None:
        assert get_filing_deadline("AETNA") == 90
        assert get_filing_deadline("BCBS") == 180
        assert get_filing_deadline("CHAMPVA") == 365
        assert get_filing_deadline("CIGNA") == 90
        assert get_filing_deadline("HUMANA") == 365
        assert get_filing_deadline("MEDICAID") == 365
        assert get_filing_deadline("TRICARE") == 365
        assert get_filing_deadline("UHC") == 180
        assert get_filing_deadline("UNITED") == 180
