"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.setFeedTemplate = setFeedTemplate;
const util_1 = require("../../util");
const getMajorVersion_1 = require("./_internal/getMajorVersion");
/**
 * Sets the feed template for a given feed format and version. Always use this function
 * to update feed templates rather than interacting with the feeds configuration object directly.
 * @param opts.feedsConfig - the raw feeds configuration object
 * @param opts.format - the feed format
 * @param opts.version - the feed version
 * @param opts.updatedTemplate - the updated feed template
 * @returns a new feeds configuration object with the updated template
 */
function setFeedTemplate(opts) {
    const { feedsConfig, format, version, updatedTemplate } = opts;
    const updatedConfig = (0, util_1.cloneObject)(feedsConfig);
    if (format === "dcat-us") {
        setDcatUsConfig(updatedConfig, version, updatedTemplate);
    }
    else if (format === "dcat-ap") {
        setDcatApConfig(updatedConfig, version, updatedTemplate);
    }
    else if (format === "rss") {
        setRssConfig(updatedConfig, version, updatedTemplate);
    }
    else {
        throw new Error("Unsupported feed format");
    }
    return updatedConfig;
}
function setDcatApConfig(feedsConfig, version, config) {
    if ((0, getMajorVersion_1.getMajorVersion)(version) === "2") {
        feedsConfig.dcatAP2XX = config;
        return;
    }
    throw new Error("Unsupported DCAT AP Version");
}
function setDcatUsConfig(feedsConfig, version, config) {
    if ((0, getMajorVersion_1.getMajorVersion)(version) === "1") {
        feedsConfig.dcatUS1X = config;
        return;
    }
    if ((0, getMajorVersion_1.getMajorVersion)(version) === "3") {
        feedsConfig.dcatUS3X = config;
        return;
    }
    throw new Error("Unsupported DCAT US Version");
}
function setRssConfig(feedsConfig, version, config) {
    if ((0, getMajorVersion_1.getMajorVersion)(version) === "2") {
        feedsConfig.rss2 = config;
        return;
    }
    throw new Error("Unsupported RSS Version");
}
//# sourceMappingURL=setFeedTemplate.js.map