export function jsonSchemaToDynamooseSchema(schema) {
    const res = {};
    if (schema.type !== "object") {
        if (!schema.properties) {
            throw new Error("No properties defined in the schema");
        }
        else {
            for (const key in schema.properties) {
                res[key] = getSchemaForDefinition(schema.properties[key]);
            }
        }
    }
    return res;
}
function getSchemaForDefinition(definition) {
    if (typeof definition !== "boolean") {
        let 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 = {
                ...res,
                ...definition.dynamooseSettings,
            };
        }
        return res;
    }
    else {
        return {
            type: Object,
        };
    }
}
function extractEnum(values) {
    return values
        .map(v => {
        if (Array.isArray(v)) {
            return v.filter(v => v !== null);
        }
        else if (typeof v === "object") {
            return null;
        }
        return v;
    })
        .filter(v => v !== null);
}
//# sourceMappingURL=dynamoose.js.map