"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseIssueBroadcastArgs = parseIssueBroadcastArgs;
const catalog_1 = require("../../i18n/catalog");
const shared_1 = require("./shared");
function parseIssueBroadcastArgs(args, locale = catalog_1.DEFAULT_APP_LOCALE) {
    const state = {
        issueIds: [],
        statuses: [],
        labels: [],
        dryRun: false,
    };
    for (let index = 0; index < args.length; index += 1) {
        const token = args[index];
        const value = args[index + 1];
        switch (token) {
            case "--message":
                (0, shared_1.assignIssueBroadcastMessage)(state, {
                    kind: "text",
                    text: (0, shared_1.parseNonEmptyFreeformTextArg)(token, (0, shared_1.requireOptionValue)(token, value, locale), locale),
                }, locale);
                index += 1;
                break;
            case "--message-file":
                (0, shared_1.assignIssueBroadcastMessage)(state, {
                    kind: "file",
                    path: (0, shared_1.requireOptionValue)(token, value, locale),
                }, locale);
                index += 1;
                break;
            case "--issue":
                (0, shared_1.assignIssueBroadcastSelector)(state, "issue", locale);
                state.issueIds.push(...(0, shared_1.parseIssueIds)(token, value, locale));
                index += 1;
                break;
            case "--open":
                (0, shared_1.assignIssueBroadcastSelector)(state, "open", locale);
                break;
            case "--status":
                state.statuses.push((0, shared_1.parseIssueBroadcastStatus)((0, shared_1.requireOptionValue)(token, value, locale), locale));
                index += 1;
                break;
            case "--label":
                state.labels.push((0, shared_1.requireOptionValue)(token, value, locale));
                index += 1;
                break;
            case "--dry-run":
                state.dryRun = true;
                break;
            default:
                throw new Error((0, catalog_1.translate)(locale, "cli.parser.issue.broadcast.unknownOption", {
                    token: token ?? "",
                }));
        }
    }
    return (0, shared_1.buildIssueBroadcastArgs)(state, locale);
}
