"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var utils_1 = require("./utils");
var graphql_1 = require("graphql");
var mapParametersToArguments = function (parameters, resource) {
    return utils_1.keyMap(parameters, function (parameter, parameterDetail) {
        var description = parameterDetail.description, required = parameterDetail.required, type = parameterDetail.type, enumDetails = parameterDetail.enum, enumDescriptions = parameterDetail.enumDescriptions;
        var gqlType = (function () {
            if (enumDetails) {
                var enumValues_1 = {};
                enumDetails.forEach(function (enumName, index) {
                    var v = { value: enumName, description: null };
                    if (enumDescriptions)
                        v.description = enumDescriptions[index];
                    var enumKeyVal = enumName.replace(/\s/g, '_').replace(/-/g, '_');
                    if (!Number.isNaN(+enumName[0])) {
                        enumKeyVal = "_" + enumKeyVal;
                    }
                    if (enumKeyVal === 'true')
                        enumKeyVal = 'TRUE';
                    enumValues_1[enumKeyVal] = v;
                });
                var uniqueEnumNames_1 = {};
                var getUniqueEnumName = function (enumName) {
                    if (uniqueEnumNames_1[enumName] === undefined) {
                        uniqueEnumNames_1[enumName] = 0;
                    }
                    else {
                        uniqueEnumNames_1[enumName]++;
                    }
                    return "" + enumName + (uniqueEnumNames_1[enumName] > 0 ? uniqueEnumNames_1[enumName] : '');
                };
                var enumName = "" + utils_1.upperFirst(parameter
                    .replace('$.', 'dollardot')
                    .replace(/-/g, '')
                    .replace(/\./g, '')) + utils_1.upperFirst(resource) + "EnumParam";
                return new graphql_1.GraphQLEnumType({
                    name: getUniqueEnumName(enumName),
                    values: enumValues_1
                });
            }
            switch (type) {
                case 'string':
                    return graphql_1.GraphQLString;
                case 'boolean':
                    return graphql_1.GraphQLBoolean;
                case 'integer':
                    return graphql_1.GraphQLInt;
            }
            console.log('Unknown argument type', type);
            return graphql_1.GraphQLString;
        })();
        return {
            type: required ? new graphql_1.GraphQLNonNull(gqlType) : gqlType,
            description: description
        };
    }, function (key) {
        return key
            .replace('$.', 'dollardot')
            .replace(/-/g, '')
            .replace(/\./g, '');
    });
};
exports.mapParametersToArguments = mapParametersToArguments;
//# sourceMappingURL=mapParametersToArguments.js.map