from __future__ import annotations

from uuid import uuid4

from app.modules.agent.engine.orchestrator.execution_context import ExecutionContext
from app.modules.agent.engine.orchestrator.models import ArtifactType, EvidenceItem


class ActionSupport:
    def put(self, ctx: ExecutionContext, key: str, artifact_type: ArtifactType, value, *, meta: dict | None = None) -> str:
        item = ctx.artifacts.put(key=key, artifact_type=artifact_type, content=value, meta=meta)
        return item.artifact_id

    def get(self, ctx: ExecutionContext, key: str, default=None):
        return ctx.artifacts.get_content(key, default)

    def add_evidence(self, ctx: ExecutionContext, *, source_type: str, source_ref: str, snippet: str, score: float = 0.8) -> str:
        evidence = EvidenceItem(
            evidence_id=f"evidence_{uuid4().hex}",
            source_type=source_type,
            source_ref=source_ref,
            snippet=(snippet or "").strip()[:600],
            score=max(0.0, min(1.0, float(score))),
        )
        ctx.evidences.put_many([evidence])
        return evidence.evidence_id
