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

from __future__ import annotations

from speclogician.presentation.ctx import RenderCtx
from speclogician.presentation.models.data_artifact import (
    DataArtifactCorePM,
    DocRefPM,
    SrcCodeRefPM,
)

from speclogician.data.refs import DocRef, SrcCodeRef  # adjust if needed


def _build_core(art_id: str) -> DataArtifactCorePM:
    return DataArtifactCorePM(art_id=art_id)


def build_doc_ref_pm(d: DocRef, ctx: RenderCtx) -> DocRefPM:
    # Text is the artifact; keep it unless you want a separate ctx flag for "heavy text"
    text = d.text if getattr(ctx, "show_code", True) else d.text
    return DocRefPM(
        core=_build_core(d.art_id),
        text=text,
        meta=d.meta,
    )


def build_src_code_ref_pm(s: SrcCodeRef, ctx: RenderCtx) -> SrcCodeRefPM:
    show = getattr(ctx, "show_code", True)
    return SrcCodeRefPM(
        core=_build_core(s.art_id),
        src_code=s.src_code if show else "",
        language=s.language,
        file_path=s.file_path,
        iml_code=s.iml_code if show else None,
        meta=s.meta,
    )