"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.userPropertiesValidation = void 0;
const CommonFunctions = __importStar(require("../../common-functions/common-functions"));
const fs = __importStar(require("fs"));
const os = __importStar(require("os"));
const path = __importStar(require("path"));
const ConsoleMessages_1 = require("./ConsoleMessages");
class UserPropertiesValidation {
    constructor() {
    }
    async checkParameters(userProperties) {
        if (!userProperties) {
            throw new Error(ConsoleMessages_1.Messages.optionsNotProvided);
        }
        if (userProperties &&
            (userProperties.jsonDir === null || typeof userProperties.jsonDir === 'undefined' || userProperties.jsonDir === '')) {
            throw new Error(ConsoleMessages_1.Messages.jsonPathNotProvided);
        }
        userProperties = this.initializeParameters(userProperties);
        const result = await CommonFunctions.fileSystemFunctions.checkFolder(userProperties.reportPath);
        if (!result) {
            const tzoffset = new Date().getTimezoneOffset() * 60000;
            userProperties.reportPath = path.join(os.tmpdir(), 'multiple_cucumber_report', new Date(Date.now() - tzoffset).toISOString().substr(0, 19)).replace('T', '___').replace(/:/g, '_').replace(/-/g, '_');
            await fs.promises.mkdir(userProperties.reportPath, { recursive: true });
        }
        return userProperties;
    }
    initializeParameters(userProperties) {
        userProperties.saveReportInMongoDb = typeof userProperties.saveReportInMongoDb === 'undefined'
            ? false
            : userProperties.saveReportInMongoDb;
        userProperties.isLinkToServer = typeof userProperties.isLinkToServer === 'undefined'
            ? false
            : userProperties.isLinkToServer;
        userProperties.saveCollectedJSON = typeof userProperties.saveCollectedJSON === 'undefined'
            ? false
            : userProperties.saveCollectedJSON;
        userProperties.projectName = typeof userProperties.projectName === 'undefined'
            ? ''
            : userProperties.projectName;
        userProperties.showExecutionTime = typeof userProperties.showExecutionTime === 'undefined'
            ? true
            : userProperties.showExecutionTime;
        userProperties.date = typeof userProperties.date === 'undefined'
            ? new Date()
            : userProperties.date;
        userProperties.expandStepsNotPassed = typeof userProperties.expandStepsNotPassed === 'undefined'
            ? true
            : userProperties.expandStepsNotPassed;
        userProperties.navigateToFeatureIfThereIsOnlyOne = typeof userProperties.navigateToFeatureIfThereIsOnlyOne === 'undefined'
            ? true
            : userProperties.navigateToFeatureIfThereIsOnlyOne;
        userProperties.openReportInBrowser = typeof userProperties.openReportInBrowser === 'undefined'
            ? false
            : userProperties.openReportInBrowser;
        userProperties.disableLog = typeof userProperties.disableLog === 'undefined'
            ? false
            : userProperties.disableLog;
        userProperties.server = typeof userProperties.server === 'undefined'
            ? {
                serverPort: 3100,
            }
            : userProperties.server;
        userProperties.mongoDb = typeof userProperties.mongoDb === 'undefined'
            ? {
                collections: {
                    features: 'Features',
                    outputs: 'Outputs',
                    reports: 'Reports',
                    scenarios: 'Scenarios',
                    steps: 'Steps'
                },
                dbHost: 'localhost',
                dbName: 'multiple-cucumber-html-reports',
                dbPort: 27017,
            }
            : userProperties.mongoDb;
        userProperties.metadata = typeof userProperties.metadata === 'undefined' ? {} : userProperties.metadata;
        return userProperties;
    }
}
exports.userPropertiesValidation = new UserPropertiesValidation();
//# sourceMappingURL=UserPropertiesValidation.js.map