#
#   Imandra Inc.
#
#   speclogician/presentation/builders/scenario.py
#

from __future__ import annotations

from speclogician.presentation.ctx import RenderCtx
from speclogician.modeling.scenario import Scenario, Missing, Inconsistent
from speclogician.presentation.models.scenario import (
    ScenarioPM,
    ScenarioStatusPM,
)


def build_scenario_pm(sc: Scenario, ctx: RenderCtx) -> ScenarioPM:
    # status
    st = sc.component_status
    if isinstance(st, Missing):
        status = ScenarioStatusPM(
            kind="missing",
            missing_preds=list(st.missing_preds),
            missing_trans=list(st.missing_trans),
        )
    elif isinstance(st, Inconsistent):
        status = ScenarioStatusPM(kind="inconsistent")
    else:
        status = ScenarioStatusPM(kind="valid")

    return ScenarioPM(
        comp_id=sc.comp_id,
        name=sc.name,
        status=status,
        given=list(sc.given),
        when=list(sc.when),
        then=list(sc.then),
        given_preds_consistent=sc.given_preds_consistent,
        when_preds_consistent=sc.when_preds_consistent,
        all_preds_consistent=sc.all_preds_consistent,
    )