"""Tests for validate_async() and validate_batch_async()."""

from __future__ import annotations

import asyncio

from claim_validator import validate_async, validate_batch_async


def _valid_claim() -> dict:
    return {
        "billing_provider_npi": "1234567893",
        "subscriber_id": "XYZ123456",
        "patient_first_name": "Jane",
        "patient_last_name": "Doe",
        "patient_dob": "1990-01-15",
        "patient_gender": "F",
        "payer_id": "BCBS001",
        "diagnosis_codes": [{"code": "J06.9", "pointer": 1}],
        "lines": [
            {
                "procedure_code": "99213",
                "diagnosis_pointers": [1],
                "charge_amount": 150.00,
                "service_date_from": "2026-01-15",
            },
        ],
    }


def _invalid_claim() -> dict:
    """Claim that passes Pydantic but fails domain validators."""
    return {
        "billing_provider_npi": "1234567893",
        "subscriber_id": "",
        "patient_first_name": "",
        "patient_last_name": "",
        "payer_id": "",
        "diagnosis_codes": [{"code": "Z99.99", "pointer": 1}],
        "lines": [
            {
                "procedure_code": "00000",
                "diagnosis_pointers": [1],
                "charge_amount": 150.00,
                "service_date_from": "2026-01-15",
            },
        ],
    }


class TestValidateAsync:
    """Tests for validate_async()."""

    def test_valid_claim(self) -> None:
        result = asyncio.run(validate_async(_valid_claim()))
        assert result.passed is True

    def test_invalid_claim(self) -> None:
        result = asyncio.run(validate_async(_invalid_claim()))
        assert result.passed is False
        assert len(result.findings) > 0


class TestValidateBatchAsync:
    """Tests for validate_batch_async()."""

    def test_multiple_claims(self) -> None:
        results = asyncio.run(
            validate_batch_async([_valid_claim(), _valid_claim()])
        )
        assert len(results) == 2
        assert all(r.passed is True for r in results)
