"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.IocdPlatformArgs = void 0;
const constants_1 = require("../../../constants");
/**
 * Utility for building command-line arguments used to start
 * the IO.Connect Desktop platform.
 *
 * Responsibilities:
 * - `buildExecArgs`: prepares runtime flags for Chromium/Electron,
 *   including devtools port, optional inspect port, logging, and
 *   any additional start arguments.
 * - `generate`: prepares arguments for loading a system.json file
 *   and optional override files. Ensures paths are absolute and
 *   formats them into the `config=...` / `configOverrides` syntax
 *   expected by the platform.
 *
 * Together, these methods allow the launcher service to assemble
 * the exact CLI args needed when spawning the desktop executable.
 */
class IocdPlatformArgs {
    static buildExecArgs(options) {
        const { devtoolsPort, startArgs = [], enableLogging } = options;
        const execArgs = [
            `--remote-debugging-port=${devtoolsPort}`,
            `--remote-debugging-address=${constants_1.LOCALHOST}`,
            '--remote-allow-origins=*',
        ];
        if (enableLogging) {
            execArgs.push('--enable-logging');
        }
        if (startArgs.length > 0) {
            execArgs.push('--', ...startArgs);
        }
        return execArgs;
    }
}
exports.IocdPlatformArgs = IocdPlatformArgs;
IocdPlatformArgs.generate = (systemJson, configOverrides) => {
    const configArg = `config=${systemJson}`;
    const args = [configArg];
    if (configOverrides.length) {
        args.push('configOverrides');
        configOverrides.forEach((p, i) => {
            args.push(`config${i}=${p}`);
        });
        args.push('configMergeArrays');
    }
    return args;
};
