import { BestAgentError } from "@best-agent/foundation";
import type { PhaseResultEnvelope } from "@best-agent/protocol";

export function parseVerifyPhaseVerdict(phaseResult?: PhaseResultEnvelope): {
  message: string;
  status: "fail" | "pass";
} {
  if (!phaseResult?.candidateVerdict) {
    throw new BestAgentError(
      "PHASE_RESULT_INVALID",
      "Verify phases must return a structured phase_result candidate verdict.",
    );
  }
  return {
    message: phaseResult.candidateVerdict.summary,
    status: phaseResult.candidateVerdict.status === "satisfied" ? "pass" : "fail",
  };
}
