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

from __future__ import annotations

from datetime import datetime
from typing import Literal

from pydantic import BaseModel, Field

from speclogician.modeling.predicates import PredicateType
from speclogician.utils import IMLValidity


class LinkedArtifactsPM(BaseModel):
    total: int = 0
    test_traces: int = 0
    log_traces: int = 0
    doc_refs: int = 0
    src_code_refs: int = 0
    unresolved_ids: int = 0
    art_ids: list[str] = Field(default_factory=list)


class PredicatePM(BaseModel):
    kind: Literal["state_predicate", "action_predicate"]  # matches your model
    comp_id: str
    name: str
    last_updated: datetime

    pred_type: PredicateType
    signature: str

    src_code: str = ""
    iml: str = ""

    is_iml_valid: IMLValidity = IMLValidity.UNKNOWN
    iml_error: str | None = None

    links: LinkedArtifactsPM = Field(default_factory=LinkedArtifactsPM)


class TransitionPM(BaseModel):
    kind: Literal["transition"] = "transition"
    comp_id: str
    name: str
    last_updated: datetime

    signature: str

    src_code: str = ""
    iml: str = ""

    is_iml_valid: IMLValidity = IMLValidity.UNKNOWN
    iml_error: str | None = None

    links: LinkedArtifactsPM = Field(default_factory=LinkedArtifactsPM)