/**
 * ParamDef contract — canonical parameter descriptor for all CLEO operations.
 *
 * This module is the SINGLE SOURCE OF TRUTH for the `ParamDef` type.
 * All packages that describe operation parameters MUST import from here.
 *
 * @packageDocumentation
 * @module @cleocode/contracts/operations/params
 */
/**
 * Convert an array of `ParamDef` entries into a `Record<string, CittyArgDef>`
 * that can be passed directly to `defineCommand({ args: ... })`.
 *
 * Mapping rules:
 * - `type: 'boolean'`  → citty `type: 'boolean'`
 * - `type: 'string'`   → citty `type: 'string'`; `type: 'enum'` when `enum` is set
 * - `type: 'number'`   → citty `type: 'string'` (caller must `parseInt`/`parseFloat`)
 * - `type: 'array'`    → citty `type: 'string'` (caller handles splitting)
 * - `cli.positional`   → citty `type: 'positional'`
 * - `cli.short`        → citty `alias`
 * - `enum`             → citty `options` with citty `type: 'enum'`
 *
 * @param params - The `ParamDef[]` from an `OperationDef`.
 * @returns A `Record<string, CittyArgDef>` ready for use as `args` in `defineCommand`.
 */
export function paramsToCittyArgs(params) {
    const result = {};
    for (const param of params) {
        const argName = param.cli?.flag ?? param.name;
        const arg = {
            description: param.description,
        };
        if (param.cli?.positional === true) {
            arg.type = 'positional';
            arg.required = param.required;
        }
        else if (param.enum !== undefined && param.enum.length > 0) {
            arg.type = 'enum';
            arg.options = [...param.enum];
            if (param.required)
                arg.required = true;
        }
        else if (param.type === 'boolean') {
            arg.type = 'boolean';
        }
        else {
            // string, number, and array all map to citty 'string'
            // (number/array require caller-side parsing after arg extraction)
            arg.type = 'string';
            if (param.required)
                arg.required = true;
        }
        if (param.cli?.short !== undefined) {
            arg.alias = param.cli.short.replace(/^-/, '');
        }
        result[argName] = arg;
    }
    return result;
}
//# sourceMappingURL=params.js.map