#
#   Imandra Inc.
#
#   speclogician/presentation/models/state_diff.py
#

from __future__ import annotations

from typing import Any, Literal
from pydantic import BaseModel, Field

from speclogician.state.diff import ComparisonOutcome


class DiffRowPM(BaseModel):
    label: str
    before: Any
    after: Any
    outcome: ComparisonOutcome = ComparisonOutcome.UNKNOWN
    message: str = ""


class DiffSectionPM(BaseModel):
    title: str
    rows: list[DiffRowPM] = Field(default_factory=list)

    def empty(self) -> bool:
        return not self.rows


class ProgressMetricsPM(BaseModel):
    """Quantified progress metrics computed from the current (after) state."""
    # Percentage of scenarios that are valid (not missing components, not inconsistent)
    scenarios_valid_pct: float | None = None
    # Percentage of scenarios reachable from initial states
    reachability_pct: float | None = None
    # Percentage of components (predicates + transitions) with valid IML
    components_valid_pct: float | None = None
    # Percentage of components linked to at least one artifact
    linked_artifacts_pct: float | None = None
    # Number of complement regions (0 = full coverage, lower is better)
    complement_regions: int | None = None


class StateDiffPM(BaseModel):
    kind: Literal["state_diff"] = "state_diff"
    has_changes: bool
    sections: list[DiffSectionPM] = Field(default_factory=list)
    progress: ProgressMetricsPM = Field(default_factory=ProgressMetricsPM)