const { DataTypes } = require('sequelize');

module.exports = (sequelize) => {
    const Bank = sequelize.define('bank', {
        id: {
            type: DataTypes.INTEGER,
            autoIncrement: true,
            primaryKey: true
        },
        creation: { type: DataTypes.DATE, allowNull: false },
        modified: { type: DataTypes.DATE, allowNull: false },
        modified_by: { type: DataTypes.INTEGER, allowNull: false },
        owner: { type: DataTypes.INTEGER, allowNull: false },
        enabled: { type: DataTypes.BOOLEAN, allowNull: false },

        // main
        name: { type: DataTypes.STRING(50), allowNull: false },
        display_name: { type: DataTypes.STRING(50), allowNull: false },
        code: { type: DataTypes.STRING(50), allowNull: false },

        // fk
    }, {
        tableName: 'banks',
        freezeTableName: true
    });

    /**
     * Associates the Bank model with other models.
     * @param {object} models - The models to associate with.
     * @description
     */
    Bank.associate = (models) => {
        Bank.hasMany(models.BankAccount, { foreignKey: "bank_id", as: "bankaccounts" });
    };

    return Bank;
};
