"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TypeIsForienKeyAddColumn = void 0;
const core_1 = require("@asapjs/core");
const typeGenerator_1 = require("./generators/typeGenerator");
const index_1 = require("./index");
// sequelize-typescript
const foreign_key_service_1 = require("sequelize-typescript/dist/associations/foreign-key/foreign-key-service");
const attribute_service_1 = require("sequelize-typescript/dist/model/column/attribute-service");
const TypeIsForienKeyAddColumn = (target, type, key) => {
    if (!type.toSequelize) {
        core_1.logger.error('@asapjs/sequelize :: TypeIs.FOREIGNKEY에 toSequelize가 정의되지 않았습니다.');
        process.exit(1);
    }
    const { extraData, table } = type.toSequelize();
    (0, foreign_key_service_1.addForeignKey)(target.prototype, table, key);
    if (extraData) {
        // 지정한 type이 없을 경우 INT로 지정
        const type = (extraData === null || extraData === void 0 ? void 0 : extraData.type) || index_1.TypeIs.INT();
        const sequelizeType = type().toSequelize();
        (0, attribute_service_1.addAttribute)(target.prototype, key, Object.assign(Object.assign({}, extraData), sequelizeType));
    }
};
exports.TypeIsForienKeyAddColumn = TypeIsForienKeyAddColumn;
const TypeIsForeignKey = (0, typeGenerator_1.typeGenerator)((table, extraData) => ({
    __name: 'foreignkey',
    toSequelize: () => ({
        table,
        extraData,
    }),
}));
exports.default = TypeIsForeignKey;
//# sourceMappingURL=foreignkey.js.map