"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.runLabelsCommand = runLabelsCommand;
const control_plane_config_1 = require("../config/control-plane-config");
const catalog_1 = require("../i18n/catalog");
const factory_1 = require("../platform/auth/factory");
const provider_resolution_1 = require("../platform/provider-resolution");
const factory_2 = require("../platform/ticket-tracker/factory");
async function runLabelsCommand(cwd, options) {
    const loadedConfig = await (0, control_plane_config_1.loadConfig)(cwd);
    const locale = loadedConfig.i18n.defaultLanguage;
    switch (options.action) {
        case "sync":
            return runLabelsSyncCommand(cwd, locale);
    }
    throw new Error((0, catalog_1.translate)(locale, "cli.parser.labels.unknownCommand", {
        action: options.action,
    }));
}
async function runLabelsSyncCommand(cwd, locale) {
    const { config } = (0, provider_resolution_1.resolveSupportedProviders)(await (0, control_plane_config_1.loadConfig)(cwd));
    const authProvider = (0, factory_1.createAuthProvider)(config);
    const createdRequirements = await (0, factory_2.syncTicketTrackerWorkflowSchema)(config, authProvider);
    if (createdRequirements.length === 0) {
        console.log((0, catalog_1.translate)(locale, "labels.command.alreadyInSync"));
        return 0;
    }
    console.log((0, catalog_1.translate)(locale, "labels.command.synced", {
        names: createdRequirements
            .map((requirement) => requirement.name)
            .join(", "),
    }));
    return 0;
}
