#
#   Imandra Inc.
#
#   speclogician/presentation/preview/fixtures/spec.py
#

from __future__ import annotations

from speclogician.presentation.ctx import RenderCtx
from speclogician.presentation.models.spec import SpecPM, SpecCountsPM

from .domain_model import make_domain_model_pm
from .scenario_complement import make_scenario_complement_pm


# -----------------------------------------------------------------------------
# internal constructors
# -----------------------------------------------------------------------------

def _spec_minimal(ctx: RenderCtx) -> SpecPM:
    dm = make_domain_model_pm(ctx, variant="minimal")
    return SpecPM(
        domain=dm,
        counts=SpecCountsPM(
            num_sc_total=0,
            num_sc_missing=0,
            num_sc_matched=0,
            num_sc_inconsistent=0,
            num_sc_conflicted=0,
        ),
        scenario_names=[],
        scenario_complement=None,
    )


def _spec_typical(ctx: RenderCtx) -> SpecPM:
    dm = make_domain_model_pm(ctx, variant="typical")
    return SpecPM(
        domain=dm,
        counts=SpecCountsPM(
            num_sc_total=9,
            num_sc_missing=1,
            num_sc_matched=0,
            num_sc_inconsistent=0,
            num_sc_conflicted=0,
        ),
        scenario_names=[
            "scenario_1",
            "scenario_2",
            "scenario_3",
            "order_rejects_on_max_qty",
            "order_accepts_on_small_qty",
        ],
        scenario_complement=make_scenario_complement_pm("typical"),
    )


def _spec_edge(ctx: RenderCtx) -> SpecPM:
    dm = make_domain_model_pm(ctx, variant="edge")
    # stress: lots of scenarios, some missing + inconsistent + conflicted
    names = [f"scenario_{i}" for i in range(1, 26)]
    return SpecPM(
        domain=dm,
        counts=SpecCountsPM(
            num_sc_total=len(names),
            num_sc_missing=5,
            num_sc_matched=12,
            num_sc_inconsistent=3,
            num_sc_conflicted=2,
        ),
        scenario_names=names,
        scenario_complement=make_scenario_complement_pm("edge"),
    )


# -----------------------------------------------------------------------------
# public entrypoint (matches other fixtures)
# -----------------------------------------------------------------------------

def make_spec_pm(ctx: RenderCtx, variant: str = "typical") -> SpecPM:
    v = (variant or "typical").strip().lower()
    if v == "minimal":
        return _spec_minimal(ctx)
    if v == "edge":
        return _spec_edge(ctx)
    return _spec_typical(ctx)


# -----------------------------------------------------------------------------
# renderer adapter (matches other fixtures style)
# -----------------------------------------------------------------------------

def render(pm: SpecPM, ctx: RenderCtx):
    from speclogician.presentation.renderers.spec import render_spec
    return render_spec(pm, ctx=ctx)