import { KEY_MODEL } from '../impl/model/key-model.const';
import { Metadata } from './metadata';
export function metadataForClass(modelConstructor) {
    return new Metadata(modelConstructor);
}
export function metadataForModel(modelConstructor) {
    var modelMetadata = Reflect.getMetadata(KEY_MODEL, modelConstructor);
    if (!modelMetadata) {
        throw new Error("make sure the @Model decorator is present on the model " + modelConstructor.name);
    }
    return modelMetadata;
}
/**
 *
 * @param {ModelConstructor<T>} modelConstructor
 * @param {keyof T} propertyKey Either the name of the property or the name of the
 * @returns {PropertyMetadata<T>}
 */
export function metadataForProperty(modelConstructor, propertyKey) {
    if (modelConstructor) {
        var modelMetadata = Reflect.getMetadata(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(function (property) { return property.name === propertyKey || property.nameDb === propertyKey; }) ||
                null);
        }
    }
    return null;
}
//# sourceMappingURL=metadata-helper.js.map