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