"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Table = void 0;
const sequelize_typescript_1 = require("sequelize-typescript");
const belongsto_1 = require("../types/belongsto");
const foreignkey_1 = require("../types/foreignkey");
const dbml_1 = require("../dbml");
const console_1 = require("../console");
const types_1 = require("../types");
function Table(options) {
    return function (target) {
        const modelName = options.tableName || target.name;
        const types = (0, types_1.getTypesData)(target);
        Object.entries(types).forEach(([key, type]) => {
            if (type.__name === 'foreignkey') {
                (0, foreignkey_1.TypeIsForienKeyAddColumn)(target, type, key);
            }
            else if (type.__name === 'belongsto') {
                (0, belongsto_1.TypeIsBelongsToAddColumn)(target, type, key);
            }
            else {
                (0, sequelize_typescript_1.addAttribute)(target.prototype, key, type.toSequelize());
            }
        });
        if ((options === null || options === void 0 ? void 0 : options.timestamps) !== false) {
            (0, sequelize_typescript_1.addOptions)(target.prototype, {
                createdAt: 'created_at',
                timestamps: true,
            });
            (0, sequelize_typescript_1.addOptions)(target.prototype, {
                updatedAt: 'updated_at',
                timestamps: true,
            });
        }
        // DBML GENERATE를 위한 Table 정보 저장
        (0, dbml_1.addTable)(modelName, target.name, types);
        (0, console_1.addTable)(modelName, target.name, types);
        // sequelize-typescript
        (0, sequelize_typescript_1.setModelName)(target.prototype, modelName);
        (0, sequelize_typescript_1.addOptions)(target.prototype, Object.assign(Object.assign({}, options), { charset: 'utf8mb4', collate: 'utf8mb4_general_ci' }));
    };
}
exports.Table = Table;
//# sourceMappingURL=index.js.map