"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseWorkflowScheduleOption = parseWorkflowScheduleOption;
exports.parseWorkflowScheduledRunOption = parseWorkflowScheduledRunOption;
exports.parseWorkflowFirstRunOption = parseWorkflowFirstRunOption;
const recurring_1 = require("./recurring");
const workflow_option_parse_shared_1 = require("./workflow-option-parse-shared");
function parseWorkflowScheduleOption(tokens, index, optionSpec, existingSchedule, existingScheduledRun, inlineTrailingText) {
    return (0, workflow_option_parse_shared_1.parseExclusiveWorkflowCommandOptionUpdate)(tokens, index, inlineTrailingText, [existingSchedule, existingScheduledRun], "conflicting-schedule-options", (value) => {
        const schedule = {
            mode: optionSpec.mode,
            value,
        };
        return (0, recurring_1.isWorkflowScheduleInputValid)(schedule) ? { schedule } : null;
    });
}
function parseWorkflowScheduledRunOption(tokens, index, optionSpec, existingSchedule, existingScheduledRun, inlineTrailingText) {
    return (0, workflow_option_parse_shared_1.parseExclusiveWorkflowCommandOptionUpdate)(tokens, index, inlineTrailingText, [existingSchedule, existingScheduledRun], "conflicting-schedule-options", (value) => {
        const scheduledRun = (0, workflow_option_parse_shared_1.parseWorkflowRunAtOrAfterOptionValue)(optionSpec.mode, value);
        return scheduledRun === null ? null : { scheduledRun };
    });
}
function parseWorkflowFirstRunOption(tokens, index, optionSpec, existingFirstRun, inlineTrailingText) {
    const mode = optionSpec.mode;
    if (mode === "now") {
        const conflict = (0, workflow_option_parse_shared_1.rejectExistingWorkflowCommandOptionValues)([existingFirstRun], "conflicting-schedule-options", inlineTrailingText);
        if (conflict !== undefined) {
            return conflict;
        }
        return (0, workflow_option_parse_shared_1.buildWorkflowCommandOptionFlagUpdateResult)({
            firstRun: {
                mode: "now",
                value: null,
            },
        }, inlineTrailingText);
    }
    return (0, workflow_option_parse_shared_1.parseExclusiveWorkflowCommandOptionUpdate)(tokens, index, inlineTrailingText, [existingFirstRun], "conflicting-schedule-options", (value) => {
        const firstRun = (0, workflow_option_parse_shared_1.parseWorkflowRunAtOrAfterOptionValue)(mode, value);
        return firstRun === null ? null : { firstRun };
    });
}
