"""Output schema for eligibility interpreter AI chain."""
from __future__ import annotations

from pydantic import BaseModel, Field

from claim_validator.constants import Severity
from claim_validator.models.results import Finding, ValidatorOutput


class EligibilityDetail(BaseModel):
    """Parsed eligibility details from the payer response."""

    coverage_active: bool
    plan_name: str | None = None
    copay: float | None = None
    deductible_remaining: float | None = None
    out_of_pocket_remaining: float | None = None


class EligibilityInterpreterOutput(BaseModel):
    """Structured output from the eligibility interpreter AI chain."""

    eligible: bool
    details: EligibilityDetail
    warnings: list[str] = Field(default_factory=list)
    reasoning: str

    def to_validator_output(self) -> ValidatorOutput:
        """Convert to the standard ValidatorOutput used by the pipeline."""
        return ValidatorOutput(
            validator_name="eligibility_interpreter_ai",
            findings=[
                Finding(
                    code="AI_ELIG_COVERAGE_CONCERN",
                    message=w,
                    severity=Severity.WARNING,
                    field_name="",
                )
                for w in self.warnings
            ],
        )
