"use strict";
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.jsonSchemaToDynamooseSchema = void 0;
function jsonSchemaToDynamooseSchema(schema) {
    var res = {};
    if (schema.type !== "object") {
        if (!schema.properties) {
            throw new Error("No properties defined in the schema");
        }
        else {
            for (var key in schema.properties) {
                res[key] = getSchemaForDefinition(schema.properties[key]);
            }
        }
    }
    return res;
}
exports.jsonSchemaToDynamooseSchema = jsonSchemaToDynamooseSchema;
function getSchemaForDefinition(definition) {
    if (typeof definition !== "boolean") {
        var res = {
            type: Object,
        };
        switch (definition.type) {
            case "number":
                res = {
                    type: Number,
                };
                if (definition.enum && !definition.enum.includes(null)) {
                    res.enum = extractEnum(definition.enum);
                }
                break;
            case "string":
                res = {
                    type: String,
                };
                if (definition.enum && !definition.enum.includes(null)) {
                    res.enum = definition.enum;
                }
                break;
        }
        if (definition.dynamooseSettings) {
            res = __assign(__assign({}, res), definition.dynamooseSettings);
        }
        return res;
    }
    else {
        return {
            type: Object,
        };
    }
}
function extractEnum(values) {
    return values
        .map(function (v) {
        if (Array.isArray(v)) {
            return v.filter(function (v) { return v !== null; });
        }
        else if (typeof v === "object") {
            return null;
        }
        return v;
    })
        .filter(function (v) { return v !== null; });
}
//# sourceMappingURL=dynamoose.js.map