"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateObjectPageInterfaceV4 = generateObjectPageInterfaceV4;
exports.generateListReportInterfaceV4 = generateListReportInterfaceV4;
exports.generateFreestyleInterfaceV4 = generateFreestyleInterfaceV4;
exports.generateFPMCustomPageInterfaceV4 = generateFPMCustomPageInterfaceV4;
const utils_1 = require("../../common/utils");
const _1 = require(".");
const ux_specification_types_1 = require("@sap/ux-specification-types");
const utils_2 = require("../utils/utils");
const importProject_1 = require("../../common/importProject");
const i18n_1 = require("../../../i18n/i18n");
/**
 * Generates the app specific schema of an object page out of the generic schema for the same page.
 * Generic types are replaced by information from the app specific annotations.
 *
 * @param genericSchema - generic JSON schema of a list report
 * @param entitySetName - the base entity set of the given page
 * @param annotations - list of all annotation files (file content plus URI as identifier)
 * @param manifest - manifest.json of the app
 * @param {ExtensionLogger} logger - Logger class for logging messages
 * @param {FileData[]} fragments - list of fragment files and their content
 * @param {string} contextPath - contextPath of the actual (object) page
 * @param {object} genericMacrosSchema - generic macros schema of the app
 * @param {FeatureToggle[]} [featureToggles] - array of supported features
 * @returns the app specific JSON schema
 */
function generateObjectPageInterfaceV4(genericSchema, entitySetName, annotations, manifest, logger, fragments, contextPath, genericMacrosSchema, featureToggles) {
    (0, i18n_1.initI18n)();
    const serviceAVT = (0, utils_1.parseAndMergeAndConvert)(annotations, logger);
    const { entitySet, entityType } = (0, importProject_1.getEntityTypeEntitySetFromContextPath)(serviceAVT, contextPath, entitySetName, logger);
    const generateParameters = {
        templateType: ux_specification_types_1.TemplateType.ListReportObjectPageV4,
        fioriElementsVersion: ux_specification_types_1.FioriElementsVersion.v4,
        manifest,
        fragments,
        serviceAVT,
        logger,
        entitySet,
        entityType,
        featureToggles
    };
    return (0, _1.generateObjectPageSchemaV4)(generateParameters, genericSchema, contextPath, genericMacrosSchema);
}
/**
 * Generates the app specific schema of a list report out of the generic schema.
 * Generic types are replaced by information from the app specific annotations.
 *
 * @param {TemplateType} templateType - the template type allows distinguishing LR and ALP
 * @param genericSchema - generic JSON schema of a list report
 * @param entitySetName - the base entity set of the given page
 * @param annotations - list of all annotation files (file content plus URI as identifier)
 * @param {ExtensionLogger} logger - Logger class for logging messages
 * @param manifest - manifest.json of the app
 * @param contextPath - the context path of the actual page
 * @returns the app specific JSON schema
 */
function generateListReportInterfaceV4(templateType, genericSchema, entitySetName, annotations, logger, manifest, contextPath) {
    (0, i18n_1.initI18n)();
    const serviceAVT = (0, utils_1.parseAndMergeAndConvert)(annotations, logger);
    const { entitySet, entityType } = (0, importProject_1.getEntityTypeEntitySetFromContextPath)(serviceAVT, contextPath, entitySetName, logger);
    const generateParameters = {
        templateType,
        fioriElementsVersion: ux_specification_types_1.FioriElementsVersion.v4,
        manifest,
        serviceAVT,
        logger,
        entitySet,
        entityType
    };
    const templateName = templateType === ux_specification_types_1.TemplateType.ListReportObjectPageV4 ? ux_specification_types_1.v4.FE_TEMPLATE_V4_LIST_REPORT : ux_specification_types_1.v4.FE_TEMPLATE_V4_ALP;
    return (0, _1.generateListReportSchemaV4)(generateParameters, genericSchema, templateName, contextPath);
}
/**
 * Generates the app specific schema of a freestyle page out of the generic schema.
 * Generic types are replaced by information from the app specific annotations.
 *
 * @param templateType - the template type allows distinguishing LR and ALP
 * @param genericSchema - generic JSON schema of a list report
 * @param annotations - list of all annotation files (file content plus URI as identifier)
 * @param manifest - manifest.json of the app
 * @param _entitySetName - the name of the entity set (optional)
 * @param logger - Logger class for logging messages
 * @returns the app specific JSON schema
 */
function generateFreestyleInterfaceV4(templateType, genericSchema, annotations, manifest, _entitySetName, logger) {
    const serviceAVT = (0, utils_1.parseAndMergeAndConvert)(annotations, logger);
    const generateParameters = {
        templateType,
        fioriElementsVersion: ux_specification_types_1.FioriElementsVersion.v4,
        manifest,
        serviceAVT,
        logger
    };
    return (0, _1.generateFreestyleSchemaV4)(generateParameters, genericSchema);
}
/**
 * Generates the app specific schema of a FPM Custom page out of the generic schema.
 *
 * @param genericSchema - generic JSON schema of a list report.
 * @param routingId - page id in routing.
 * @param manifest - manifest.json of the app.
 * @param views - array of views.xml files.
 * @param annotations - list of all annotation files (file content plus URI as identifier)
 * @param [featureToggles] - array of supported features.
 * @param [logger] - Logger class for logging messages.
 * @returns the app specific JSON schema.
 */
function generateFPMCustomPageInterfaceV4(genericSchema, routingId, manifest, views, annotations, featureToggles, logger) {
    let schema = {};
    if ((0, utils_1.isFeatureSupported)(featureToggles, ux_specification_types_1.Features.BuildingBlocks)) {
        const serviceAVT = (0, utils_1.parseAndMergeAndConvert)(annotations, logger);
        const viewData = (0, utils_2.getPageCustomViewFile)(views || [], routingId, manifest, logger);
        schema = viewData?.file.fileContent
            ? (0, _1.generateMacrosSchemaDefinition)(genericSchema, viewData, serviceAVT, logger)
            : {};
    }
    return schema;
}
//# sourceMappingURL=generate.js.map