"""Pydantic types for parser event output."""
from __future__ import annotations

from typing import Literal

from pydantic import BaseModel, Field


class GuidanceOutput(BaseModel):
    status: Literal[
        "raised", "inline_or_maintained", "lowered", "withdrawn", "not_provided", "unclear"
    ]
    scope: Literal["quarterly", "annual", "both", "unknown"]
    notes: str = ""


class SignalsOutput(BaseModel):
    demand_strength: Literal["strong", "stable", "weakening", "unknown"]
    pricing_power: Literal["present", "mixed", "absent", "unknown"]
    backlog_or_bookings: Literal["present", "mixed", "absent", "unknown"]
    customer_expansion: Literal["present", "mixed", "absent", "unknown"]
    margin_quality: Literal["improving", "stable", "deteriorating", "unknown"]


class RiskFlagsOutput(BaseModel):
    oneoff_item: bool = False
    tax_benefit: bool = False
    valuation_gain: bool = False
    non_gaap_heavy: bool = False
    financing_related: bool = False
    legal_or_regulatory_overhang: bool = False


class ConfidenceOutput(BaseModel):
    overall: float = Field(ge=0.0, le=1.0)
    event_type: float = Field(ge=0.0, le=1.0)
    event_direction: float = Field(ge=0.0, le=1.0)
    guidance: float = Field(ge=0.0, le=1.0)
    risk_flags: float = Field(ge=0.0, le=1.0)


class EvidenceItem(BaseModel):
    label: str
    text_span: str
    section_hint: str
    confidence: float = Field(ge=0.0, le=1.0)


class ParserEventOutput(BaseModel):
    schema_version: str = "1.0.0"
    document_id: str
    parser_kind: Literal["rule", "llm", "merged"]
    event_type: Literal[
        "earnings_release",
        "guidance_update",
        "material_contract",
        "regulatory_or_approval",
        "capital_markets_or_financing",
        "management_change",
        "litigation_or_investigation",
        "other_material_event",
        "unknown",
    ]
    event_direction: Literal["bullish", "bearish", "mixed", "neutral", "unknown"]
    event_date: str  # ISO date
    filing_time_bucket: Literal["pre_market", "regular_hours", "post_market", "unknown"]
    headline: str = ""
    summary: str
    guidance: GuidanceOutput
    signals: SignalsOutput
    risk_flags: RiskFlagsOutput
    evidence: list[EvidenceItem] = Field(default_factory=list)
    confidence: ConfidenceOutput
    warnings: list[str] = Field(default_factory=list)
