"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (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.getAllParams = exports.Preview = exports.Outcome = exports.Credentials = exports.Button = exports.Recordset = exports.Pipeline = exports.Keys = exports.Template = exports.ParamRef = exports.Definition = exports.JavaScript = exports.Json = exports.Selector = exports.Boolean = exports.Number = exports.Enum = exports.String = exports.PARAMS_SYMBOL = void 0;
const util = __importStar(require("../util/index.js"));
exports.PARAMS_SYMBOL = Symbol('Params');
function String(spec = {}) {
    return paramDecorator('string', { ...spec });
}
exports.String = String;
function Enum(spec) {
    return paramDecorator('enum', { ...spec });
}
exports.Enum = Enum;
function Number(spec = {}) {
    return paramDecorator('number', { ...spec });
}
exports.Number = Number;
function Boolean(spec = {}) {
    return paramDecorator('boolean', { ...spec });
}
exports.Boolean = Boolean;
function Selector(spec = {}) {
    return paramDecorator('selector', { ...spec });
}
exports.Selector = Selector;
function Json(spec = {}) {
    return paramDecorator('json', { ...spec });
}
exports.Json = Json;
function JavaScript(spec = {}) {
    return paramDecorator('javascript', { ...spec });
}
exports.JavaScript = JavaScript;
function Definition(spec = {}) {
    return paramDecorator('definition', { ...spec });
}
exports.Definition = Definition;
function ParamRef(spec = {}) {
    return paramDecorator('ref', { ...spec });
}
exports.ParamRef = ParamRef;
function Template(spec = {}) {
    return paramDecorator('template', { ...spec });
}
exports.Template = Template;
function Keys(spec = {}) {
    return paramDecorator('keys', { ...spec });
}
exports.Keys = Keys;
function Pipeline(spec = {}) {
    return paramDecorator('pipeline', { ...spec });
}
exports.Pipeline = Pipeline;
function Recordset(spec) {
    return paramDecorator('recordset', { ...spec });
}
exports.Recordset = Recordset;
function Button(spec = {}) {
    return paramDecorator('button', {
        ...spec,
        serialized: false,
    });
}
exports.Button = Button;
function Credentials(spec) {
    const configs = Array.isArray(spec.configs) ? spec.configs : [spec.configs];
    return paramDecorator('credentials', { ...spec, configs });
}
exports.Credentials = Credentials;
function Outcome(spec = {}) {
    return paramDecorator('outcome', { ...spec });
}
exports.Outcome = Outcome;
exports.Preview = Outcome;
function paramDecorator(type, spec) {
    return (target, propertyKey) => {
        const params = Reflect.getOwnMetadata(exports.PARAMS_SYMBOL, target) || [];
        params.push({
            value: null,
            serialized: true,
            label: util.humanize(propertyKey),
            ...spec,
            name: propertyKey,
            type,
        });
        Reflect.defineMetadata(exports.PARAMS_SYMBOL, params, target);
    };
}
function getAllParams(target) {
    let params = [];
    let proto = target;
    while (proto !== Object.prototype) {
        const ownParams = Reflect.getOwnMetadata(exports.PARAMS_SYMBOL, proto) || [];
        const filteredParams = ownParams.filter(param => !params.some(p => p.name === param.name));
        params = filteredParams.concat(params);
        proto = Object.getPrototypeOf(proto);
    }
    return params;
}
exports.getAllParams = getAllParams;
//# sourceMappingURL=params.js.map