"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.WORKFLOW_OVERRIDE_OPTIONS = exports.WORKFLOW_DELETE_REVIEWED_DRAFT_OPTION = exports.WORKFLOW_UPDATE_REVIEWED_DRAFT_OPTION = exports.WORKFLOW_CREATE_REVIEWED_DRAFT_OPTION = exports.ISSUE_REVIEWED_DRAFT_OPTION = exports.SAVE_DRAFT_OPTIONS = void 0;
const issue_completion_1 = require("../config/issue-completion");
const issue_override_option_registry_1 = require("../workflows/issue-override-option-registry");
const workflow_command_side_options_1 = require("../workflows/workflow-command-side-options");
exports.SAVE_DRAFT_OPTIONS = [
    "--save-draft: Save a machine-local reusable draft JSON and exit without applying changes.",
];
exports.ISSUE_REVIEWED_DRAFT_OPTION = "--apply-draft <path|->: Create the issue from a reviewed reusable draft JSON. Do not combine with prompt/manual inputs, --save-draft, metadata options, or workflow options.";
exports.WORKFLOW_CREATE_REVIEWED_DRAFT_OPTION = "--apply-draft <path|->: Apply a reviewed workflow create draft JSON. Do not combine with prompt/manual inputs, --save-draft, or template overrides.";
exports.WORKFLOW_UPDATE_REVIEWED_DRAFT_OPTION = "--apply-draft <path|->: Apply a reviewed workflow update draft JSON. Do not combine with --path, --prompt, --template-set, or --save-draft.";
exports.WORKFLOW_DELETE_REVIEWED_DRAFT_OPTION = "--apply-draft <path|->: Apply a reviewed workflow delete draft JSON. Do not combine with --path, --cleanup-references, --dry-run, or --save-draft.";
const ISSUE_OVERRIDE_OPTION_DESCRIPTIONS = {
    "issue-completion-target": "Choose whether completed issue work pauses on the issue or moves to a pull request.",
    "pr-review": "Choose whether pull request review runs.",
    "pr-merge": "Choose whether pull requests are merged manually or automatically.",
    "max-ai-runs": "Override the AI run count limit.",
    "max-ai-hours": "Override the AI work-hour limit.",
    "default-reviewers": "Override default PR reviewers. Comma-separated and repeatable.",
    "default-worker": "Override ordinary execution workers for this issue.",
    "thinking-worker": "Select the first worker for planning and draft-style runs; unavailable selections fall back to workers.default.",
    "foreign-approval-scope": "Override which foreign issues require approval.",
    "recurring-max-active-children": "Override the maximum open recurring child issues for this parent.",
    "recurring-update-child-title-after-plan": "Override whether recurring child issue titles are updated after planning.",
    "followup-proposal": "Choose follow-up proposal generation: off, if_needed, or always.",
    "followup-proposal-approval": "Choose follow-up proposal approval: auto, confirm, or confirm_if_needed.",
    "followup-preferred-workflow-template": "Add priority follow-up template hints for recommendation only; not an allowlist and does not force creation. Comma-separated and repeatable.",
    "followup-auto-maintain-templates": "Allow follow-up workflow selection to request or refresh missing templates when needed.",
    "followup-max-main-work-issues": "Override the automatic mainWork follow-up issue cap for this source item.",
    "followup-max-maintenance-issues": "Override the automatic maintenance follow-up issue cap for this source item.",
    "workflow-start-new-plan": "Override start approval for newly planned work.",
    "workflow-start-replan": "Override start approval for post-start replans.",
    "workflow-start-scope": "Override whether start approval applies to issue work only or issue and PR work.",
    "requirements-setup-skills": "Choose whether missing required skills create setup issues automatically or ask for confirmation.",
    "requirements-setup-mcp": "Choose whether missing required MCP servers create setup issues automatically or ask for confirmation.",
};
const SIDE_WORKFLOW_OPTION_BY_FLAG = new Map(workflow_command_side_options_1.SIDE_WORKFLOW_COMMAND_OPTION_SPECS.map((spec) => [
    spec.flag,
    `${spec.flag} <auto|auto_select|no_template|path>: Store the ${spec.surface} workflow selector. auto may request a missing template when that target runs; auto_select chooses an existing candidate, or falls back to no_template without workflow_select when no candidates exist; no_template uses the built-in default workflow for that target.`,
]));
const ISSUE_OVERRIDE_OPTION_BY_FLAG = new Map(issue_override_option_registry_1.ISSUE_OVERRIDE_OPTION_REGISTRY.map((option) => [
    option.flag,
    renderIssueOverrideOption(option),
]));
exports.WORKFLOW_OVERRIDE_OPTIONS = [
    "--workflow <auto|auto_select|no_template|path>: Set the active workflow selector. auto may request a missing template; auto_select chooses an existing candidate, or falls back to no_template without workflow_select when no candidates exist; no_template uses the built-in default workflow.",
    getSideWorkflowOption("--pr-workflow"),
    getSideWorkflowOption("--unplanned-workflow"),
    "  Automatic follow-up publication requires fresh workflow_closing provenance. During PR merge finalization, AlpacaLoop verifies the PR head or merge commit from a synchronized source/base workspace; if freshness cannot be proven, it stops automatic follow-up creation and asks for human review.",
    "--run-at <time> / --run-after <duration>: Schedule one future run.",
    "--every <duration> / --cron <expr>: Create a recurring parent issue.",
    "--first-run-at <time> / --first-run-after <duration> / --first-run-now: Control the first run of a recurring issue.",
    "--stop-at <time> / --stop-after <duration> / --stop-after-runs <count> / --stop-off: Control recurring auto-stop behavior.",
    "--schedule-off: Clear one-shot and recurring scheduling.",
    "--base-branch <value|default>: Override the stored base branch for this issue's workflow state and PR merge target.",
    getIssueOverrideOption("issue-completion-target"),
    getIssueOverrideOption("pr-review"),
    getIssueOverrideOption("pr-merge"),
    getIssueOverrideOption("default-reviewers"),
    getIssueOverrideOption("default-worker"),
    getIssueOverrideOption("thinking-worker"),
    getIssueOverrideOption("max-ai-runs"),
    getIssueOverrideOption("max-ai-hours"),
    getIssueOverrideOption("recurring-max-active-children"),
    getIssueOverrideOption("recurring-update-child-title-after-plan"),
    getIssueOverrideOption("followup-proposal"),
    getIssueOverrideOption("followup-proposal-approval"),
    getIssueOverrideOption("followup-preferred-workflow-template"),
    getIssueOverrideOption("followup-auto-maintain-templates"),
    getIssueOverrideOption("followup-max-main-work-issues"),
    getIssueOverrideOption("followup-max-maintenance-issues"),
    getIssueOverrideOption("foreign-approval-scope"),
    getIssueOverrideOption("workflow-start-new-plan"),
    getIssueOverrideOption("workflow-start-replan"),
    getIssueOverrideOption("workflow-start-scope"),
    getIssueOverrideOption("requirements-setup-skills"),
    getIssueOverrideOption("requirements-setup-mcp"),
];
function renderIssueOverrideOption(option) {
    return `--${option.flag} ${renderIssueOverrideValue(option)}: ${ISSUE_OVERRIDE_OPTION_DESCRIPTIONS[option.flag]}`;
}
function getSideWorkflowOption(flag) {
    const option = SIDE_WORKFLOW_OPTION_BY_FLAG.get(flag);
    if (option === undefined) {
        throw new Error(`Missing side workflow help option: ${flag}`);
    }
    return option;
}
function getIssueOverrideOption(flag) {
    const option = ISSUE_OVERRIDE_OPTION_BY_FLAG.get(flag);
    if (option === undefined) {
        throw new Error(`Missing issue override help option: ${flag}`);
    }
    return option;
}
function renderIssueOverrideValue(option) {
    if (option.flag === "issue-completion-target") {
        return `<${issue_completion_1.ISSUE_COMPLETION_TARGET_CLI_VALUES.join("|")}>`;
    }
    if (option.flag === "pr-review") {
        return `<${issue_completion_1.PULL_REQUEST_REVIEW_POLICY_CLI_VALUES.join("|")}>`;
    }
    if (option.flag === "pr-merge") {
        return `<${issue_completion_1.PULL_REQUEST_MERGE_POLICY_CLI_VALUES.join("|")}>`;
    }
    switch (option.kind) {
        case "boolean":
            return "<true|false|default>";
        case "integer":
            if (hasNumericBounds(option)) {
                return `<${String(option.min)}..${String(option.max)}|default>`;
            }
            return "<count|default>";
        case "number":
            return option.allowDisable ? "<hours|off|default>" : "<number|default>";
        case "enum":
            return `<${[...(option.enumValues ?? []), "default"].join("|")}>`;
        case "string-array":
            return "<value[,value...]|default>";
        case "workflow-template-list":
            return "<path|no_template[,path...]|default>";
        case "worker":
            return "<worker-id|default>";
    }
}
function hasNumericBounds(option) {
    return ("min" in option &&
        "max" in option &&
        typeof option.min === "number" &&
        typeof option.max === "number");
}
