"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const key_model_const_1 = require("../impl/model/key-model.const");
const metadata_1 = require("./metadata");
function metadataForClass(modelConstructor) {
    return new metadata_1.Metadata(modelConstructor);
}
exports.metadataForClass = metadataForClass;
function metadataForModel(modelConstructor) {
    const modelMetadata = Reflect.getMetadata(key_model_const_1.KEY_MODEL, modelConstructor);
    if (!modelMetadata) {
        throw new Error(`make sure the @Model decorator is present on the model ${modelConstructor.name}`);
    }
    return modelMetadata;
}
exports.metadataForModel = metadataForModel;
/**
 *
 * @param {ModelConstructor<T>} modelConstructor
 * @param {keyof T} propertyKey Either the name of the property or the name of the
 * @returns {PropertyMetadata<T>}
 */
function metadataForProperty(modelConstructor, propertyKey) {
    if (modelConstructor) {
        const modelMetadata = Reflect.getMetadata(key_model_const_1.KEY_MODEL, modelConstructor);
        if (modelConstructor && !modelMetadata) {
            throw new Error(`make sure the @Model decorator was added to the given modelConstructor ${Object.hasOwnProperty('name') ? modelConstructor.name : modelConstructor}, was not able to find model metadata`);
        }
        if (modelMetadata.properties) {
            return (modelMetadata.properties.find(property => property.name === propertyKey || property.nameDb === propertyKey) ||
                null);
        }
    }
    return null;
}
exports.metadataForProperty = metadataForProperty;
//# sourceMappingURL=metadata-helper.js.map