/** @fileoverview A typed parseArgs utility that wraps yargs-parser with Node.js parseArgs-like API. */
'use strict';
Object.defineProperty(exports, "__esModule", { value: true });
exports.commonParseArgsConfig = void 0;
exports.parseArgs = parseArgs;
const yargs_parser_1 = require("../external/yargs-parser");
/**
 * Parse command-line arguments with a Node.js parseArgs-compatible API.
 * Uses yargs-parser internally for robust argument parsing.
 */
function parseArgs(config = {}) {
    const { allowNegative = false, allowPositionals = true, args = process.argv.slice(2), options = {}, strict = true, } = config;
    // Convert parseArgs options to yargs-parser options.
    const yargsOptions = {
        boolean: [],
        string: [],
        array: [],
        alias: {},
        default: {},
        'unknown-options-as-args': !strict,
        'parse-numbers': false,
        'parse-positional-numbers': false,
        'boolean-negation': !allowNegative,
        'halt-at-non-option': !allowPositionals,
        configuration: {
            'strip-aliased': false,
            'strip-dashed': true,
        },
    };
    // Process each option configuration.
    for (const { 0: key, 1: optionConfig } of Object.entries(options)) {
        const { default: defaultValue, multiple, short, type } = optionConfig;
        // Set the option type.
        if (type === 'boolean') {
            yargsOptions.boolean.push(key);
        }
        else if (type === 'string') {
            yargsOptions.string.push(key);
        }
        // Handle multiple values (arrays).
        if (multiple) {
            yargsOptions.array.push(key);
        }
        // Set short alias.
        if (short) {
            yargsOptions.alias[short] = key;
        }
        // Set default value.
        if (defaultValue !== undefined) {
            yargsOptions.default[key] = defaultValue;
        }
    }
    // Parse the arguments.
    const parsed = (0, yargs_parser_1)(args, yargsOptions);
    // Extract positional arguments.
    const positionals = parsed._ || [];
    // Remove the positionals array from values to match Node.js parseArgs behavior.
    const { _, ...values } = parsed;
    // Ensure positionals are strings.
    const stringPositionals = positionals.map(String);
    return {
        values: values,
        positionals: stringPositionals,
        raw: parsed,
    };
}
/**
 * Common parseArgs configuration for Socket registry scripts.
 */
exports.commonParseArgsConfig = {
    options: {
        force: {
            type: 'boolean',
            short: 'f',
            default: false,
        },
        quiet: {
            type: 'boolean',
            short: 'q',
            default: false,
        },
    },
    strict: false,
};
exports.default = parseArgs;
