#
#   Imandra Inc.
#
#   speclogician/data/artifact.py
#

from __future__ import annotations

import uuid
from pydantic import BaseModel, Field, field_validator
from ..utils import IMLValidity

class Artifact(BaseModel):
    """
    Base class for an Artifact
    """
    # Assigned task ID, new one created if not provided
    art_id : str | None = Field(default_factory=lambda: str(uuid.uuid4()))

    @field_validator("art_id", mode="before")
    @classmethod
    def _coerce_none_to_uuid(cls, v:str|None):
        if v is None:
            return str(uuid.uuid4())
        return v

class TraceIMLValidity(BaseModel):
    iml_valid: IMLValidity
    err: str | None = None

class TraceScenarioMatchResult(BaseModel):
    scenario_name: str
    iml_valid: bool
    err: str | None = None
    when_matches: bool = False
    given_matches: bool = False
    transition_matches: bool = False

class TraceArtifact(Artifact):
    """
    Concrete execution trace:
    - given : concrete state value
    - when  : optional concrete action value
    - then  : optional resulting state value
    """

    given: str                              # state
    when: str | None = None                 # action (optional)
    then: str | None = None                 # state (optional)

    iml_validity: TraceIMLValidity = Field(
        default_factory=lambda: TraceIMLValidity(
            iml_valid=IMLValidity.UNKNOWN,
            err=None,
        )
    )
    time: str = ""

class DataArtifact(Artifact):
    """
    Data may be either source code or documentation
    """
    pass