"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseIssueArgs = parseIssueArgs;
// biome-ignore lint/nursery/noExcessiveLinesPerFile: Issue argument parsing stays grouped so nested command behavior remains auditable.
const catalog_1 = require("../../i18n/catalog");
const issue_show_options_1 = require("../../commands/issue-show-options");
const types_1 = require("../../issues/types");
const types_2 = require("../../workflows/types");
const workflow_option_normalizer_1 = require("../../workflows/workflow-option-normalizer");
const issue_broadcast_1 = require("./issue-broadcast");
const shared_1 = require("./shared");
function parseIssueArgs(args, locale = catalog_1.DEFAULT_APP_LOCALE) {
    const [action, ...rest] = args;
    if (!action) {
        throw new Error((0, catalog_1.translate)(locale, "cli.parser.issue.usage"));
    }
    switch (action) {
        case "approve":
            return parseIssueApproveArgs(rest, locale);
        case "start":
            return parseIssueStartArgs(rest, locale);
        case "disable":
        case "enable":
            return {
                action,
                ...parseIssueDisabledRuleArgs(rest, locale, action),
            };
        case "create":
            return parseIssueCreateArgs(rest, locale);
        case "list":
            return parseIssueListArgs(rest, locale);
        case "search":
            return parseIssueSearchArgs(rest, locale);
        case "show":
            return {
                action,
                ...parseIssueShowArgs(rest, locale),
            };
        case "broadcast":
            return {
                action,
                ...(0, issue_broadcast_1.parseIssueBroadcastArgs)(rest, locale),
            };
        case "followup":
            return parseIssueFollowupArgs(rest, locale);
        case "log":
            return parseIssueLogArgs(rest, locale);
        case "unlock":
            return {
                action,
                ...parseIssueUnlockArgs(rest, locale),
            };
        default:
            throw new Error((0, catalog_1.translate)(locale, "cli.parser.issue.unknownCommand", { action }));
    }
}
function parseIssueApproveArgs(args, locale) {
    const values = {};
    for (let index = 0; index < args.length; index += 1) {
        const token = args[index];
        const value = args[index + 1];
        switch (token) {
            case "--issue":
                values.issueId = (0, shared_1.parseSingleIssueId)(token, value, locale);
                index += 1;
                break;
            default:
                throw new Error((0, catalog_1.translate)(locale, "cli.parser.issue.approve.unknownOption", {
                    token: token ?? "",
                }));
        }
    }
    return {
        action: "approve",
        issueId: (0, shared_1.requireParsedOption)(values.issueId, "--issue", locale),
    };
}
function parseIssueStartArgs(args, locale) {
    const values = {};
    for (let index = 0; index < args.length; index += 1) {
        const token = args[index];
        const value = args[index + 1];
        switch (token) {
            case "--issue":
                values.issueId = (0, shared_1.parseSingleIssueId)(token, value, locale);
                index += 1;
                break;
            default:
                throw new Error((0, catalog_1.translate)(locale, "cli.parser.issue.start.unknownOption", {
                    token: token ?? "",
                }));
        }
    }
    return {
        action: "start",
        issueId: (0, shared_1.requireParsedOption)(values.issueId, "--issue", locale),
    };
}
function parseIssueDisabledRuleArgs(args, locale, action) {
    const values = {};
    for (let index = 0; index < args.length; index += 1) {
        const token = args[index];
        const value = args[index + 1];
        switch (token) {
            case "--issue":
                values.issueIds = (0, shared_1.parseIssueIds)(token, value, locale);
                index += 1;
                break;
            default:
                throw new Error((0, catalog_1.translate)(locale, `cli.parser.issue.${action}.unknownOption`, {
                    token: token ?? "",
                }));
        }
    }
    if (!values.issueIds || values.issueIds.length === 0) {
        throw new Error((0, catalog_1.translate)(locale, "cli.parser.missingRequiredOption", {
            option: "--issue",
        }));
    }
    return { issueIds: values.issueIds };
}
function parseIssueFollowupArgs(args, locale) {
    const values = {
        dryRun: false,
    };
    for (let index = 0; index < args.length; index += 1) {
        const token = args[index];
        const value = args[index + 1];
        switch (token) {
            case "--issue":
                values.issueId = (0, shared_1.parseSingleIssueId)(token, value, locale);
                index += 1;
                break;
            case "--prompt":
                values.prompt = (0, shared_1.parseRequiredOptionValue)(token, value, locale, (optionValue) => (0, shared_1.parseNonEmptyFreeformTextArg)(token, optionValue, locale));
                index += 1;
                break;
            case "--workflow":
                values.workflowSelector = parseIssueFollowupWorkflowSelector((0, shared_1.parseRequiredOptionValue)(token, value, locale, (optionValue) => (0, shared_1.parseNonEmptyStringArg)(token, optionValue, locale)), locale);
                index += 1;
                break;
            case "--dry-run":
                values.dryRun = true;
                break;
            default:
                throw new Error((0, catalog_1.translate)(locale, "cli.parser.issue.followup.unknownOption", {
                    token: token ?? "",
                }));
        }
    }
    if (values.issueId === undefined) {
        throw new Error((0, catalog_1.translate)(locale, "cli.parser.issue.followup.usage"));
    }
    return {
        action: "followup",
        issueId: values.issueId,
        dryRun: values.dryRun,
        ...(values.prompt !== undefined ? { prompt: values.prompt } : {}),
        ...(values.workflowSelector !== undefined
            ? { workflowSelector: values.workflowSelector }
            : {}),
    };
}
function parseIssueFollowupWorkflowSelector(value, locale) {
    if (value === types_2.WORKFLOW_TEMPLATE_AUTO_SENTINEL) {
        return { mode: "auto" };
    }
    if (value === types_2.WORKFLOW_TEMPLATE_AUTO_SELECT_SENTINEL) {
        return { mode: "auto_select" };
    }
    if (value === types_2.WORKFLOW_TEMPLATE_NO_TEMPLATE_SENTINEL) {
        return { mode: "no_template" };
    }
    const normalizedPath = (0, types_2.normalizeWorkflowTemplatePath)(value);
    if (normalizedPath === null) {
        throw new Error((0, catalog_1.translate)(locale, "cli.parser.issue.followup.invalidWorkflow"));
    }
    return { mode: "template", templatePath: normalizedPath };
}
// biome-ignore lint/complexity/noExcessiveLinesPerFunction: Issue create parsing keeps each CLI flag rule explicit and local.
function parseIssueCreateArgs(args, locale) {
    const values = {
        assignees: [],
        labels: [],
        disabled: false,
        saveDraft: false,
        workflowTokens: [],
    };
    for (let index = 0; index < args.length; index += 1) {
        const token = args[index];
        const value = args[index + 1];
        switch (token) {
            case "--prompt":
                values.prompt = (0, shared_1.parseRequiredOptionValue)(token, value, locale, (optionValue) => (0, shared_1.parseNonEmptyFreeformTextArg)(token, optionValue, locale));
                index += 1;
                break;
            case "--title":
                values.title = (0, shared_1.parseRequiredOptionValue)(token, value, locale, (optionValue) => (0, shared_1.parseNonEmptyStringArg)(token, optionValue, locale));
                index += 1;
                break;
            case "--body":
                assignIssueCreateBody(values, {
                    kind: "text",
                    text: (0, shared_1.parseRequiredOptionValue)(token, value, locale, (optionValue) => (0, shared_1.parseNonEmptyFreeformTextArg)(token, optionValue, locale)),
                }, locale);
                index += 1;
                break;
            case "--body-file":
                assignIssueCreateBody(values, {
                    kind: "file",
                    path: (0, shared_1.parseRequiredOptionValue)(token, value, locale, (optionValue) => (0, shared_1.parseNonEmptyStringArg)(token, optionValue, locale)),
                }, locale);
                index += 1;
                break;
            case "--apply-draft":
                values.applyDraftPath = (0, shared_1.parseRequiredOptionValue)(token, value, locale, (optionValue) => (0, shared_1.parseNonEmptyStringArg)(token, optionValue, locale));
                index += 1;
                break;
            case "--assignee":
                values.assignees.push((0, shared_1.parseRequiredOptionValue)(token, value, locale, (optionValue) => (0, shared_1.parseNonEmptyStringArg)(token, optionValue, locale)));
                index += 1;
                break;
            case "--label":
                values.labels.push((0, shared_1.parseRequiredOptionValue)(token, value, locale, (optionValue) => (0, shared_1.parseNonEmptyStringArg)(token, optionValue, locale)));
                index += 1;
                break;
            case "--milestone":
                values.milestoneRef = (0, shared_1.parseRequiredOptionValue)(token, value, locale, (optionValue) => (0, shared_1.parseNonEmptyStringArg)(token, optionValue, locale));
                index += 1;
                break;
            case "--project":
                values.projectRef = (0, shared_1.parseRequiredOptionValue)(token, value, locale, (optionValue) => (0, shared_1.parseNonEmptyStringArg)(token, optionValue, locale));
                index += 1;
                break;
            case "--disabled":
                values.disabled = true;
                break;
            case "--save-draft":
                values.saveDraft = true;
                break;
            default: {
                const consumedWorkflowOption = (0, workflow_option_normalizer_1.consumeWorkflowOptionToken)(args, index);
                if (consumedWorkflowOption !== undefined) {
                    values.workflowTokens.push(...args.slice(index, index + consumedWorkflowOption.consumedTokens));
                    index += consumedWorkflowOption.consumedTokens - 1;
                    break;
                }
                throw new Error((0, catalog_1.translate)(locale, "cli.parser.issue.create.unknownOption", {
                    token: token ?? "",
                }));
            }
        }
    }
    if (values.applyDraftPath !== undefined) {
        if (values.prompt !== undefined ||
            values.title !== undefined ||
            values.body !== undefined) {
            throw new Error((0, catalog_1.translate)(locale, "cli.parser.issue.create.applyDraftModeError"));
        }
        if (values.workflowTokens.length > 0) {
            throw new Error((0, catalog_1.translate)(locale, "cli.parser.issue.create.applyDraftWorkflowError"));
        }
        if (values.assignees.length > 0 ||
            values.labels.length > 0 ||
            values.milestoneRef !== undefined ||
            values.projectRef !== undefined ||
            values.disabled) {
            throw new Error((0, catalog_1.translate)(locale, "cli.parser.issue.create.applyDraftMetadataError"));
        }
        if (values.saveDraft) {
            throw new Error((0, catalog_1.translate)(locale, "cli.parser.issue.create.applyDraftOutputError"));
        }
        return {
            action: "create",
            mode: "apply-draft",
            applyDraftPath: values.applyDraftPath,
        };
    }
    const workflowOptions = parseIssueCreateWorkflowOptions(values.workflowTokens, locale);
    const common = {
        assignees: values.assignees,
        labels: values.labels,
        disabled: values.disabled,
        ...(values.saveDraft ? { saveDraft: true } : {}),
        ...(workflowOptions !== undefined ? { workflowOptions } : {}),
        ...(values.milestoneRef !== undefined
            ? { milestoneRef: values.milestoneRef }
            : {}),
        ...(values.projectRef !== undefined
            ? { projectRef: values.projectRef }
            : {}),
    };
    if (values.prompt !== undefined) {
        if (values.title !== undefined || values.body !== undefined) {
            throw new Error((0, catalog_1.translate)(locale, "cli.parser.issue.create.modeError"));
        }
        return {
            action: "create",
            mode: "prompt",
            prompt: values.prompt,
            ...common,
        };
    }
    if (values.title === undefined || values.body === undefined) {
        throw new Error((0, catalog_1.translate)(locale, "cli.parser.issue.create.manualError"));
    }
    return {
        action: "create",
        mode: "manual",
        title: values.title,
        body: values.body,
        ...common,
    };
}
function assignIssueCreateBody(values, body, locale) {
    if (values.body !== undefined) {
        throw new Error((0, catalog_1.translate)(locale, "cli.parser.issue.create.bodyError"));
    }
    values.body = body;
}
function parseIssueCreateWorkflowOptions(tokens, locale) {
    if (tokens.length === 0) {
        return undefined;
    }
    const parsed = (0, workflow_option_normalizer_1.parseWorkflowOptionTokens)(tokens);
    if (parsed.kind !== "update") {
        const reason = parsed.kind === "invalid" ? parsed.reason : "unexpected-argument";
        throw new Error((0, catalog_1.translate)(locale, "cli.parser.issue.create.invalidWorkflowOption", {
            reason: (0, catalog_1.translate)(locale, resolveWorkflowCommandReasonKey(reason)),
        }));
    }
    if (parsed.bodyAfterCommand.trim().length > 0) {
        throw new Error((0, catalog_1.translate)(locale, "cli.parser.issue.create.invalidWorkflowOption", {
            reason: (0, catalog_1.translate)(locale, resolveWorkflowCommandReasonKey("unexpected-argument")),
        }));
    }
    return (0, workflow_option_normalizer_1.pickWorkflowCommandUpdateFields)(parsed);
}
function resolveWorkflowCommandReasonKey(reason) {
    switch (reason) {
        case "missing-options":
            return "workflow.runContext.invalidCommand.missingOptions";
        case "missing-option-value":
            return "workflow.runContext.invalidCommand.missingOptionValue";
        case "invalid-option-value":
            return "workflow.runContext.invalidCommand.invalidOptionValue";
        case "duplicate-option":
            return "workflow.runContext.invalidCommand.duplicateOption";
        case "conflicting-schedule-options":
            return "workflow.runContext.invalidCommand.conflictingScheduleOptions";
        case "unsupported-command-body":
            return "workflow.runContext.invalidCommand.unsupportedCommandBody";
        default:
            return "workflow.runContext.invalidCommand.unexpectedArgument";
    }
}
function parseIssueLogArgs(args, locale) {
    const [action, ...rest] = args;
    if (!action) {
        throw new Error((0, catalog_1.translate)(locale, "cli.parser.issue.log.usage"));
    }
    switch (action) {
        case "list":
            return parseIssueLogListArgs(rest, locale);
        case "show":
            return parseIssueLogShowArgs(rest, locale);
        case "search":
            return parseIssueLogSearchArgs(rest, locale);
        default:
            throw new Error((0, catalog_1.translate)(locale, "cli.parser.issue.log.unknownCommand", { action }));
    }
}
function parseIssueLogListArgs(args, locale) {
    if (args.length > 0) {
        throw new Error((0, catalog_1.translate)(locale, "cli.parser.issue.log.list.unknownOption", {
            token: args[0] ?? "",
        }));
    }
    return { action: "log-list" };
}
function parseIssueLogShowArgs(args, locale) {
    const values = {};
    for (let index = 0; index < args.length; index += 1) {
        const token = args[index];
        const value = args[index + 1];
        switch (token) {
            case "--issue":
                values.issueId = (0, shared_1.parseSingleIssueId)(token, value, locale);
                index += 1;
                break;
            case "--tail":
                values.tail = (0, shared_1.parseRequiredOptionValue)(token, value, locale, (optionValue) => (0, shared_1.parsePositiveIntegerArg)("--tail", optionValue, locale));
                index += 1;
                break;
            default:
                throw new Error((0, catalog_1.translate)(locale, "cli.parser.issue.log.show.unknownOption", {
                    token: token ?? "",
                }));
        }
    }
    const issueId = (0, shared_1.requireParsedOption)(values.issueId, "--issue", locale);
    return values.tail === undefined
        ? {
            action: "log-show",
            issueId,
        }
        : {
            action: "log-show",
            issueId,
            tail: values.tail,
        };
}
function parseIssueLogSearchArgs(args, locale) {
    const values = {
        context: 0,
    };
    for (let index = 0; index < args.length; index += 1) {
        const token = args[index];
        const value = args[index + 1];
        switch (token) {
            case "--query":
                values.query = (0, shared_1.parseRequiredOptionValue)(token, value, locale, (optionValue) => (0, shared_1.parseNonEmptyStringArg)("--query", optionValue, locale));
                index += 1;
                break;
            case "--context":
                values.context = (0, shared_1.parseRequiredOptionValue)(token, value, locale, (optionValue) => (0, shared_1.parseNonNegativeIntegerArg)("--context", optionValue, locale));
                index += 1;
                break;
            default:
                throw new Error((0, catalog_1.translate)(locale, "cli.parser.issue.log.search.unknownOption", {
                    token: token ?? "",
                }));
        }
    }
    return {
        action: "log-search",
        query: (0, shared_1.requireParsedOption)(values.query, "--query", locale),
        context: values.context,
    };
}
function parseIssueListArgs(args, locale) {
    const values = {
        view: "detailed",
        format: types_1.ISSUE_REPORT_FORMATS.markdown,
        assignees: [],
        me: false,
        web: false,
        viewProvided: false,
        formatProvided: false,
    };
    for (let index = 0; index < args.length; index += 1) {
        const token = args[index];
        const value = args[index + 1];
        switch (token) {
            case "--state":
                values.state = (0, shared_1.parseRequiredOptionValue)(token, value, locale, (optionValue) => (0, shared_1.parseIssueState)(optionValue, locale));
                index += 1;
                break;
            case "--label":
                values.labels ??= [];
                values.labels.push((0, shared_1.parseRequiredOptionValue)(token, value, locale, (optionValue) => optionValue));
                index += 1;
                break;
            case "--assignee":
                values.assignees.push((0, shared_1.parseRequiredOptionValue)(token, value, locale, (optionValue) => (0, shared_1.parseNonEmptyStringArg)(token, optionValue, locale)));
                index += 1;
                break;
            case "--me":
                values.me = true;
                break;
            case "--days":
                values.days = (0, shared_1.parseRequiredOptionValue)(token, value, locale, (optionValue) => (0, shared_1.parsePositiveIntegerArg)("--days", optionValue, locale));
                index += 1;
                break;
            case "--limit":
                values.limit = (0, shared_1.parseRequiredOptionValue)(token, value, locale, (optionValue) => (0, shared_1.parsePositiveIntegerArg)("--limit", optionValue, locale));
                index += 1;
                break;
            case "--web":
                values.web = true;
                break;
            case "--view":
                values.viewProvided = true;
                values.view = (0, shared_1.parseRequiredOptionValue)(token, value, locale, (optionValue) => (0, shared_1.parseIssueView)(optionValue, locale));
                index += 1;
                break;
            case "--format":
                values.formatProvided = true;
                values.format = (0, shared_1.parseRequiredOptionValue)(token, value, locale, (optionValue) => (0, shared_1.parseIssueFormat)(optionValue, locale));
                index += 1;
                break;
            default:
                throw new Error((0, catalog_1.translate)(locale, "cli.parser.issue.list.unknownOption", {
                    token: token ?? "",
                }));
        }
    }
    if (!values.web) {
        return {
            action: "list",
            ...buildIssueListReportFilters(values),
            view: values.view,
            format: values.format,
        };
    }
    if (values.viewProvided || values.formatProvided) {
        throw new Error((0, catalog_1.translate)(locale, "cli.parser.issue.list.webOutputOptionError"));
    }
    if (values.me || values.assignees.length > 0) {
        throw new Error((0, catalog_1.translate)(locale, "cli.parser.issue.list.webAssigneeOptionError"));
    }
    if (values.limit !== undefined) {
        throw new Error((0, catalog_1.translate)(locale, "cli.parser.issue.list.webLimitOptionError"));
    }
    return {
        action: "list",
        ...buildIssueListWebFilters(values),
        web: true,
    };
}
function buildIssueListWebFilters(values) {
    const filters = {};
    if (values.state !== undefined) {
        filters.state = values.state;
    }
    if (values.labels !== undefined) {
        filters.labels = values.labels;
    }
    if (values.days !== undefined) {
        filters.days = values.days;
    }
    return filters;
}
function buildIssueListReportFilters(values) {
    const filters = buildIssueListWebFilters(values);
    if (values.assignees.length > 0) {
        filters.assignees = values.assignees;
    }
    if (values.me) {
        filters.me = true;
    }
    if (values.limit !== undefined) {
        filters.limit = values.limit;
    }
    return filters;
}
function parseIssueSearchArgs(args, locale) {
    const values = {
        limit: 10,
        includePullRequests: false,
        format: types_1.ISSUE_REPORT_FORMATS.text,
    };
    for (let index = 0; index < args.length; index += 1) {
        const token = args[index];
        const value = args[index + 1];
        switch (token) {
            case "--title":
                assignIssueSearchText(values, "title", (0, shared_1.parseRequiredOptionValue)(token, value, locale, (optionValue) => (0, shared_1.parseNonEmptyStringArg)(token, optionValue, locale)), locale);
                index += 1;
                break;
            case "--query":
                assignIssueSearchText(values, "query", (0, shared_1.parseRequiredOptionValue)(token, value, locale, (optionValue) => (0, shared_1.parseNonEmptyStringArg)(token, optionValue, locale)), locale);
                index += 1;
                break;
            case "--state":
                values.state = (0, shared_1.parseRequiredOptionValue)(token, value, locale, (optionValue) => (0, shared_1.parseIssueState)(optionValue, locale));
                index += 1;
                break;
            case "--limit":
                values.limit = (0, shared_1.parseRequiredOptionValue)(token, value, locale, (optionValue) => (0, shared_1.parsePositiveIntegerArg)("--limit", optionValue, locale));
                index += 1;
                break;
            case "--include-prs":
                values.includePullRequests = true;
                break;
            case "--format":
                values.format = (0, shared_1.parseRequiredOptionValue)(token, value, locale, (optionValue) => (0, shared_1.parseIssueFormat)(optionValue, locale));
                index += 1;
                break;
            default:
                throw new Error((0, catalog_1.translate)(locale, "cli.parser.issue.search.unknownOption", {
                    token: token ?? "",
                }));
        }
    }
    return {
        action: "search",
        mode: (0, shared_1.requireParsedOption)(values.mode, "--title|--query", locale),
        text: (0, shared_1.requireParsedOption)(values.text, "--title|--query", locale),
        ...(values.state !== undefined ? { state: values.state } : {}),
        limit: values.limit,
        includePullRequests: values.includePullRequests,
        format: values.format,
    };
}
function assignIssueSearchText(values, mode, text, locale) {
    if (values.mode !== undefined || values.text !== undefined) {
        throw new Error((0, catalog_1.translate)(locale, "cli.parser.issue.search.selectorError"));
    }
    values.mode = mode;
    values.text = text;
}
function parseIssueShowArgs(args, locale) {
    const values = {
        format: types_1.ISSUE_REPORT_FORMATS.markdown,
    };
    for (let index = 0; index < args.length; index += 1) {
        const token = args[index];
        const value = args[index + 1];
        switch (token) {
            case "--issue":
                values.issueId = (0, shared_1.parseSingleIssueId)(token, value, locale);
                index += 1;
                break;
            case "--format":
                values.format = (0, shared_1.parseRequiredOptionValue)(token, value, locale, (optionValue) => (0, shared_1.parseIssueFormat)(optionValue, locale));
                index += 1;
                break;
            case "--view":
                values.view = (0, shared_1.parseRequiredOptionValue)(token, value, locale, (optionValue) => parseIssueShowView(token, optionValue, locale));
                index += 1;
                break;
            case "--parents":
                values.parentsDepth = (0, shared_1.parseRequiredOptionValue)(token, value, locale, (optionValue) => parseIssueShowDepth(token, optionValue, locale));
                index += 1;
                break;
            case "--children":
                values.childrenDepth = (0, shared_1.parseRequiredOptionValue)(token, value, locale, (optionValue) => parseIssueShowDepth(token, optionValue, locale));
                index += 1;
                break;
            case "--limit":
                values.relatedLimit = (0, shared_1.parseRequiredOptionValue)(token, value, locale, (optionValue) => parseIssueShowLimit(token, optionValue, locale));
                index += 1;
                break;
            case "--comments":
                values.commentsMode = (0, shared_1.parseRequiredOptionValue)(token, value, locale, (optionValue) => parseIssueShowCommentMode(token, optionValue, locale));
                index += 1;
                break;
            case "--pr":
                values.prMode = (0, shared_1.parseRequiredOptionValue)(token, value, locale, (optionValue) => parseIssueShowPrMode(token, optionValue, locale));
                index += 1;
                break;
            default:
                throw new Error((0, catalog_1.translate)(locale, "cli.parser.issue.show.unknownOption", {
                    token: token ?? "",
                }));
        }
    }
    return {
        issueId: (0, shared_1.requireParsedOption)(values.issueId, "--issue", locale),
        format: values.format,
        ...(values.view !== undefined ? { view: values.view } : {}),
        ...(values.parentsDepth !== undefined
            ? { parentsDepth: values.parentsDepth }
            : {}),
        ...(values.childrenDepth !== undefined
            ? { childrenDepth: values.childrenDepth }
            : {}),
        ...(values.relatedLimit !== undefined
            ? { relatedLimit: values.relatedLimit }
            : {}),
        ...(values.commentsMode !== undefined
            ? { commentsMode: values.commentsMode }
            : {}),
        ...(values.prMode !== undefined ? { prMode: values.prMode } : {}),
    };
}
function parseIssueShowView(token, value, locale) {
    if (Object.values(issue_show_options_1.ISSUE_SHOW_VIEWS).includes(value)) {
        return value;
    }
    throw new Error((0, catalog_1.translate)(locale, "cli.parser.invalidOptionValue", {
        token,
        value,
    }));
}
function parseIssueShowCommentMode(token, value, locale) {
    if (Object.values(issue_show_options_1.ISSUE_SHOW_COMMENT_MODES).includes(value)) {
        return value;
    }
    throw new Error((0, catalog_1.translate)(locale, "cli.parser.invalidOptionValue", {
        token,
        value,
    }));
}
function parseIssueShowPrMode(token, value, locale) {
    if (Object.values(issue_show_options_1.ISSUE_SHOW_PR_MODES).includes(value)) {
        return value;
    }
    throw new Error((0, catalog_1.translate)(locale, "cli.parser.invalidOptionValue", {
        token,
        value,
    }));
}
function parseIssueShowDepth(token, value, locale) {
    return value === "all"
        ? null
        : (0, shared_1.parseNonNegativeIntegerArg)(token, value, locale);
}
function parseIssueShowLimit(token, value, locale) {
    return value === "all" ? null : (0, shared_1.parsePositiveIntegerArg)(token, value, locale);
}
function parseIssueUnlockArgs(args, locale) {
    const values = {};
    for (let index = 0; index < args.length; index += 1) {
        const token = args[index];
        const value = args[index + 1];
        switch (token) {
            case "--issue":
                values.issueIds = (0, shared_1.parseIssueIds)(token, value, locale);
                index += 1;
                break;
            default:
                throw new Error((0, catalog_1.translate)(locale, "cli.parser.issue.unlock.unknownOption", {
                    token: token ?? "",
                }));
        }
    }
    if (!values.issueIds || values.issueIds.length === 0) {
        throw new Error((0, catalog_1.translate)(locale, "cli.parser.missingRequiredOption", {
            option: "--issue",
        }));
    }
    return { issueIds: values.issueIds };
}
