import { createNode, serialize, setProperty } from "../formats/enfusion-text.js";
const CONFIG_TYPE_INFO = {
    "mission-header": {
        rootType: "SCR_MissionHeader",
        subdirectory: "Missions",
    },
    faction: {
        rootType: "SCR_Faction",
        subdirectory: "Configs/Factions",
    },
    "entity-catalog": {
        rootType: "SCR_EntityCatalog",
        subdirectory: "Configs/EntityCatalogs",
    },
    "editor-placeables": {
        rootType: "SCR_PlaceableEntitiesRegistry",
        subdirectory: "Configs/Editor",
    },
};
/**
 * Generate an Enfusion .conf config file.
 */
export function generateConfig(opts) {
    const info = CONFIG_TYPE_INFO[opts.configType];
    const root = createNode(info.rootType);
    switch (opts.configType) {
        case "mission-header":
            buildMissionHeader(root, opts);
            break;
        case "faction":
            buildFaction(root, opts);
            break;
        case "entity-catalog":
            buildEntityCatalog(root, opts);
            break;
        case "editor-placeables":
            buildEditorPlaceables(root, opts);
            break;
    }
    return serialize(root);
}
function buildMissionHeader(root, opts) {
    setProperty(root, "m_sName", opts.scenarioName || opts.name);
    setProperty(root, "m_sDescription", opts.scenarioDescription || "");
    setProperty(root, "m_sWorldFile", opts.worldPath || "");
    setProperty(root, "m_sIcon", "");
    setProperty(root, "m_bIsModded", "1");
}
function buildFaction(root, opts) {
    const key = opts.factionKey || opts.name.toLowerCase().replace(/[^a-z0-9]+/g, "_");
    setProperty(root, "m_sKey", key);
    setProperty(root, "m_sName", opts.name);
    setProperty(root, "m_Color", opts.factionColor || "0,100,200,255");
    setProperty(root, "m_sFlagPath", opts.flagPath || "");
}
function buildEntityCatalog(root, opts) {
    setProperty(root, "m_sCategoryName", opts.categoryName || "Custom");
    if (opts.prefabRefs && opts.prefabRefs.length > 0) {
        const entries = createNode("m_aEntries");
        for (const ref of opts.prefabRefs) {
            const entry = createNode("SCR_EntityCatalogEntry");
            setProperty(entry, "m_sPrefab", ref);
            entries.children.push(entry);
        }
        root.children.push(entries);
    }
}
function buildEditorPlaceables(root, opts) {
    setProperty(root, "m_sCategoryName", opts.categoryName || "Custom");
    if (opts.prefabRefs && opts.prefabRefs.length > 0) {
        const entries = createNode("m_aEntries");
        for (const ref of opts.prefabRefs) {
            const entry = createNode("SCR_PlaceableEntity");
            setProperty(entry, "m_sPrefab", ref);
            entries.children.push(entry);
        }
        root.children.push(entries);
    }
}
/**
 * Get the subdirectory for a config type.
 */
export function getConfigSubdirectory(configType) {
    return CONFIG_TYPE_INFO[configType].subdirectory;
}
/**
 * Get the filename for a config.
 */
export function getConfigFilename(name) {
    return `${name}.conf`;
}
//# sourceMappingURL=config.js.map