"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LabelWorkflowStateStore = void 0;
const catalog_1 = require("../../i18n/catalog");
const workflow_labels_1 = require("./workflow-labels");
const types_1 = require("../workflow-state/types");
class LabelWorkflowStateStore {
    locale;
    workflowLabels;
    constructor(workflowLabels, locale = catalog_1.DEFAULT_APP_LOCALE) {
        this.workflowLabels = workflowLabels;
        this.locale = locale;
    }
    parse(labels) {
        return (0, workflow_labels_1.parseWorkflowStateFromLabelNames)(this.workflowLabels, labels);
    }
    project(snapshot, options = {}) {
        if (options.omitWorkflowLabels) {
            return [];
        }
        assertWorkflowLabelMappings(this.workflowLabels, snapshot, options, this.locale);
        return (0, workflow_labels_1.projectWorkflowLabelNames)(this.workflowLabels, snapshot, options);
    }
}
exports.LabelWorkflowStateStore = LabelWorkflowStateStore;
function assertWorkflowLabelMappings(workflowLabels, snapshot, options, locale) {
    if (!(options.omitReadyStatusLabel &&
        snapshot.status === types_1.WORKFLOW_STATUSES.aiReady)) {
        getRequiredWorkflowLabel((0, workflow_labels_1.getWorkflowLabelForStatus)(workflowLabels, snapshot.status), snapshot.status, locale);
    }
    for (const rule of snapshot.rules) {
        getRequiredWorkflowLabel((0, workflow_labels_1.getWorkflowLabelForRule)(workflowLabels, rule), rule, locale);
    }
}
function getRequiredWorkflowLabel(label, key, locale) {
    if (label === undefined) {
        throw new Error((0, catalog_1.translate)(locale, "workflow.stateStore.missingMapping", { key }));
    }
    return label;
}
