// Internal envelope builders. Each helper takes the resolved scope, the body, and the policy
// decision and emits the contract envelope with deterministic, redaction-aware defaults.
//
// `_` prefix marks this file as package-private — index.ts never re-exports it. Callers stay
// at the top-level capture API; this module exists to keep envelope-shape decisions in one
// place so a contract evolution (e.g. a new optional provenance field) is a one-file edit.
// Builds a MemoryProposal in the canonical "proposed, no expiry, no payload, no tags" shape.
// Capture deliberately emits a thin envelope: enriching it with payload/tags/validity is a
// downstream concern that should not introduce capture-time data the user did not say.
//
// `confidence` is hard-coded to 1.0 for explicit user intents (the user said it; we trust the
// signal fully) and 0.6 for workflow-derived candidates. Splitting that choice up to the caller
// keeps the rule explicit at the call site rather than buried here.
export function buildProposal(input, confidence) {
    const capturedAt = input.capturedAt ?? input.context.nowMs;
    const validFrom = input.validFrom ?? capturedAt;
    const proposal = {
        schemaVersion: "1",
        proposalId: input.context.newProposalId(),
        proposedAt: input.context.nowMs,
        scope: input.scope,
        type: input.type,
        body: input.body,
        tags: [],
        provenance: {
            sourceKind: input.sourceKind,
            capturedAt,
            confidence,
            sensitivity: input.sensitivity,
            ...(input.captureRationale !== undefined && { captureRationale: input.captureRationale }),
            ...(input.context.conversationId !== undefined && {
                sourceConversationId: input.context.conversationId,
            }),
            ...(input.sourceWorkflowRunId !== undefined && {
                sourceWorkflowRunId: input.sourceWorkflowRunId,
            }),
        },
        validity: { validFrom },
        initialStatus: "proposed",
    };
    return proposal;
}
// Reviewer id used for capture-emitted forget/update operations. Capture is the candidate-
// generator; the actual reviewer (the human accepting the candidate) attaches their id at the
// acceptance step. Stamping a synthetic capture-side reviewer here keeps the envelope
// well-formed for the validator without misrepresenting authorship.
const CAPTURE_REVIEWER_ID = "capture:proposed";
export function buildForget(input) {
    return {
        schemaVersion: "1",
        memoryId: input.memoryId,
        reviewerId: CAPTURE_REVIEWER_ID,
        forgottenAt: input.context.nowMs,
        reason: input.reason,
        userAcknowledgedDestructive: true,
    };
}
export function buildUpdate(input) {
    return {
        schemaVersion: "1",
        memoryId: input.memoryId,
        reviewerId: CAPTURE_REVIEWER_ID,
        updatedAt: input.context.nowMs,
        bodyPatch: input.bodyPatch,
        ...(input.reviewerNote !== undefined && { reviewerNote: input.reviewerNote }),
    };
}
