"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.generate = exports.insertReportIntoDatabase = exports.generateHtmlReport = void 0;
const feature_collector_1 = require("../feature-collector/feature-collector");
const collect_jsons_1 = require("../collect-jsons/collect-jsons");
const generate_html_1 = require("./helpers/generate-html");
const suite_formatter_1 = require("./ReportObjectsFormatters/suite-formatter");
const axios_1 = __importDefault(require("axios"));
const application_properties_validation_1 = require("../helpers/application-properties-validation");
const generateHtmlReport = async (reportConfiguration, jsonReport) => {
    const reportConfigurationInitialized = application_properties_validation_1.userPropertiesValidation.initializeReportDisplayParameters(reportConfiguration);
    await new generate_html_1.GenerateHtml(jsonReport, reportConfigurationInitialized).createHtmlPages();
};
exports.generateHtmlReport = generateHtmlReport;
// eslint-disable-next-line max-len
const insertReportIntoDatabase = async (jsonReport, userProperties) => ((await axios_1.default.post(`${userProperties.mongooseServerUrl}/insertReport`, jsonReport))).data.reportId;
exports.insertReportIntoDatabase = insertReportIntoDatabase;
const generate = async (userProperties) => {
    const checkedUserProperties = application_properties_validation_1.userPropertiesValidation.checkReportGenerationParameters(userProperties);
    const features = await new feature_collector_1.CollectFeatureFiles(checkedUserProperties).collectFeatures();
    const jsonFiles = await new collect_jsons_1.CollectJsons(checkedUserProperties).createJoinedJson();
    const jsonReport = await new suite_formatter_1.SuiteFactory(checkedUserProperties).parseJsons(jsonFiles, features);
    let reportId = null;
    if (checkedUserProperties.saveReportInMongoDb) {
        reportId = await (0, exports.insertReportIntoDatabase)(jsonReport, checkedUserProperties);
    }
    await (0, exports.generateHtmlReport)(checkedUserProperties, jsonReport);
    return reportId;
};
exports.generate = generate;
//# sourceMappingURL=generate-report.js.map