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

from __future__ import annotations

from speclogician.modeling.spec import Spec
from speclogician.presentation.ctx import RenderCtx
from speclogician.presentation.builders.domain import build_domain_model_pm
from speclogician.presentation.builders.scenario_complement import (
    build_scenario_complement_pm,
)
from speclogician.presentation.models.spec import SpecPM, SpecCountsPM


def build_spec_pm(spec: Spec, ctx: RenderCtx) -> SpecPM:
    dm_pm = build_domain_model_pm(spec.domain_model, ctx)

    counts = SpecCountsPM(
        num_sc_total=spec.num_sc_total,
        num_sc_missing=spec.num_sc_missing,
        num_sc_matched=spec.num_sc_matched,
        num_sc_inconsistent=spec.num_sc_inconsistent,
        num_sc_conflicted=spec.num_sc_conflicted,
    )

    scenario_names = [s.name for s in (spec.scenarios or [])]

    return SpecPM(
        domain=dm_pm,
        counts=counts,
        scenario_names=scenario_names,
        scenario_complement=None if ctx.compact else build_scenario_complement_pm(
            getattr(spec, "scenario_comp", None),
            ctx,
        ),
    )