"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TypeIsBelongsToAddColumn = void 0;
const core_1 = require("@asapjs/core");
const sequelize_typescript_1 = require("sequelize-typescript");
const typeGenerator_1 = require("./generators/typeGenerator");
const TypeIsBelongsToAddColumn = (target, type, key) => {
    if (!type.toSequelize) {
        core_1.logger.error('@asapjs/sequelize :: TypeIs.BELONGSTO에 toSequelize가 정의되지 않았습니다.');
        process.exit(1);
    }
    const { associatedClassGetter, optionsOrForeignKey } = type.toSequelize();
    const options = (0, sequelize_typescript_1.getPreparedAssociationOptions)(optionsOrForeignKey);
    if (!options.as)
        options.as = key;
    (0, sequelize_typescript_1.addAssociation)(target.prototype, new sequelize_typescript_1.BelongsToAssociation(associatedClassGetter, options));
};
exports.TypeIsBelongsToAddColumn = TypeIsBelongsToAddColumn;
const TypeIsBelongsTo = (0, typeGenerator_1.typeGenerator)((associatedClassGetter, optionsOrForeignKey) => ({
    __name: 'belongsto',
    toSequelize: () => ({
        associatedClassGetter,
        optionsOrForeignKey,
    }),
}));
exports.default = TypeIsBelongsTo;
//# sourceMappingURL=belongsto.js.map