"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = __importDefault(require("fs"));
exports.defaultPort = 3333;
class LocalDevServerConfiguration {
    constructor(configFilePath) {
        this._liveReload = true;
        this._endpointHeaders = [];
        this.entryPoint = '';
        if (configFilePath) {
            let jsonFileContents = null;
            if (fs_1.default.existsSync(configFilePath)) {
                try {
                    jsonFileContents = fs_1.default.readFileSync(configFilePath, 'utf-8');
                }
                catch (e) {
                    console.error(`Loading file ${configFilePath} failed with error: ${e}`);
                }
            }
            if (jsonFileContents !== null && jsonFileContents !== '') {
                try {
                    this.configFromJson = JSON.parse(jsonFileContents);
                }
                catch (e) {
                    console.error(`Loading JSON in '${configFilePath}' failed with the error ${e.message}`);
                    this.configFromJson = {};
                }
            }
            else {
                this.configFromJson = {};
            }
        }
        else {
            this.configFromJson = {};
        }
        if (this.configFromJson.hasOwnProperty('liveReload')) {
            this._liveReload = !!this.configFromJson.liveReload;
        }
    }
    get containerType() {
        return this.configFromJson.containerType || 'component';
    }
    get entryPointComponent() {
        const entryPoint = this.entryPoint || this.configFromJson.main;
        if (!entryPoint) {
            return '';
        }
        if (!entryPoint.includes('/')) {
            return `${this.namespace}/${entryPoint}`;
        }
        return entryPoint;
    }
    get namespace() {
        return 'c';
    }
    get modulesSourceDirectory() {
        return this.configFromJson.modulesSourceDirectory || '';
    }
    set modulesSourceDirectory(directory) {
        this.configFromJson.modulesSourceDirectory = directory;
    }
    get staticResourcesDirectories() {
        return this.configFromJson.staticResourcesDirectories || [];
    }
    set staticResourcesDirectories(directory) {
        this.configFromJson.staticResourcesDirectories = directory;
    }
    get customLabelsFile() {
        return this.configFromJson.customLabelsFile || '';
    }
    set customLabelsFile(file) {
        this.configFromJson.customLabelsFile = file;
    }
    get contentAssetsDirectory() {
        return this.configFromJson.contentAssetsDirectory || '';
    }
    set contentAssetsDirectory(path) {
        this.configFromJson.contentAssetsDirectory = path;
    }
    get port() {
        let port = this.configFromJson.port;
        if (port !== undefined && port !== null && port !== '') {
            return port * 1;
        }
        return exports.defaultPort;
    }
    set port(port) {
        this.configFromJson.port = port;
    }
    get api_version() {
        return this.configFromJson.api_version;
    }
    set api_version(api_version) {
        this.configFromJson.api_version = api_version;
    }
    get core_version() {
        return this.configFromJson.api_version !== undefined
            ? (parseInt(this.configFromJson.api_version, 10) * 2 +
                128).toString()
            : undefined;
    }
    get endpoint() {
        return this.configFromJson.endpoint;
    }
    set endpoint(endpoint) {
        this.configFromJson.endpoint = endpoint;
    }
    get endpointHeaders() {
        return this._endpointHeaders || [];
    }
    set endpointHeaders(endpointHeaders) {
        this._endpointHeaders = endpointHeaders;
    }
    get liveReload() {
        return this._liveReload;
    }
    set liveReload(liveReload) {
        this._liveReload = liveReload;
    }
    configureFromCliArguments(config) {
        if (config.hasOwnProperty('main')) {
            this.entryPoint = config.main;
        }
    }
}
exports.default = LocalDevServerConfiguration;
//# sourceMappingURL=LocalDevServerConfiguration.js.map