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

from __future__ import annotations

from speclogician.data.container import ArtifactContainer
from speclogician.presentation.ctx import RenderCtx

from speclogician.presentation.models.container import (
    ArtifactContainerPM,
    ArtifactContainerCountsPM,
    ArtifactContainerItemsPM,
)

from speclogician.presentation.builders.trace import build_test_trace_pm, build_log_trace_pm
from speclogician.presentation.builders.data_artifact import build_doc_ref_pm, build_src_code_ref_pm


def build_artifact_container_pm(cont: ArtifactContainer, ctx: RenderCtx) -> ArtifactContainerPM:
    counts = ArtifactContainerCountsPM(
        num_test_traces_total=cont.num_test_traces_total,
        num_test_traces_matched=cont.num_test_traces_matched,
        num_test_traces_logic_good=cont.num_test_traces_logic_good,
        num_log_traces_total=cont.num_log_traces_total,
        num_log_traces_matched=cont.num_log_traces_matched,
        num_log_traces_logic_good=cont.num_log_traces_logic_good,
        num_src_code_arts_total=cont.num_src_code_arts_total,
        num_src_code_arts_matched=cont.num_src_code_arts_matched,
        num_doc_arts_total=cont.num_doc_arts_total,
        num_doc_arts_matched=cont.num_doc_arts_matched,
    )

    items = ArtifactContainerItemsPM()

    if not ctx.show_stats_only:
        if ctx.show_traces:
            items.test_traces = [build_test_trace_pm(t, ctx) for t in cont.test_traces]
            items.log_traces = [build_log_trace_pm(t, ctx) for t in cont.log_traces]
        else:
            items.test_traces = []
            items.log_traces = []

        if ctx.show_artifacts:
            items.doc_refs = [build_doc_ref_pm(d, ctx) for d in cont.doc_ref]
            items.src_code_refs = [build_src_code_ref_pm(s, ctx) for s in cont.src_code]
        else:
            items.doc_refs = []
            items.src_code_refs = []

    return ArtifactContainerPM(counts=counts, items=items)