"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildWorkerFollowupProposalReviewContract = buildWorkerFollowupProposalReviewContract;
exports.validateWorkerFollowupProposalReviewSemanticRules = validateWorkerFollowupProposalReviewSemanticRules;
const zod_1 = require("zod");
const decision_contract_schema_1 = require("./decision-contract-schema");
const structured_contract_support_1 = require("./structured-contract-support");
const workerFollowupProposalReviewSchema = zod_1.z
    .object({
    summary: zod_1.z
        .string()
        .min(1)
        .describe("Short summary of how the human review comments changed the final follow-up candidates."),
    items: zod_1.z
        .array(decision_contract_schema_1.workerFollowupRecommendationItemSchema)
        .describe("Final follow-up issue candidates after applying the human review comments. Empty array means create no follow-up issues."),
})
    .strict()
    .describe("Follow-up proposal review result.");
function buildWorkerFollowupProposalReviewContract(input) {
    return (0, structured_contract_support_1.buildWorkerStructuredContract)({
        schema: workerFollowupProposalReviewSchema,
        example: buildWorkerFollowupProposalReviewExample(input),
        rules: [
            "Return exactly one JSON object in the decision block.",
            "Apply the review comments to the proposal candidates before approval.",
            "Delete candidates the user rejected or marked unnecessary.",
            "Modify candidates when the user asks for changed title, body, category, reason, or workflowTemplate.",
            "Add a candidate only when the review comments explicitly request an additional independent follow-up issue.",
            "Keep each item independently trackable after the source issue is closed.",
            "Approved proposal review candidates are not capped by maxIssuesPerSource, but use that value as context for what would normally be auto-created.",
            "Use an empty items array when the review comments reject all candidates.",
            "Do not include explanation fields outside summary and items.",
        ],
    });
}
function validateWorkerFollowupProposalReviewSemanticRules(_review, _input) {
    return [];
}
function buildWorkerFollowupProposalReviewExample(input) {
    return {
        summary: "Applied the review comments and kept the approved candidate list.",
        items: input.proposal.items.slice(0, 1).map((item) => ({
            category: item.category,
            title: item.title,
            body: item.body,
            reason: item.reason,
            ...(item.workflowTemplate !== undefined
                ? { workflowTemplate: item.workflowTemplate }
                : {}),
            ...(item.proposalApproval !== undefined
                ? { proposalApproval: item.proposalApproval }
                : {}),
        })),
    };
}
