module.exports = (sequelize, DataTypes) => {
  const CompanyBankDetail = sequelize.define('CompanyBankDetail', {
    id: {
      type: DataTypes.INTEGER,
      primaryKey: true,
      autoIncrement: true
    },
    company_id: {
      type: DataTypes.INTEGER,
      allowNull: false,
      references: {
        model: 'Company',
        key: 'id'
      }
    },
    account_holder_name: {
      type: DataTypes.STRING(200),
      allowNull: false
    },
    bank_name: {
      type: DataTypes.STRING(200),
      allowNull: false
    },
    account_no: {
      type: DataTypes.STRING(50),
      allowNull: false
    },
    branch: {
      type: DataTypes.STRING(200),
      allowNull: false
    },
    ifsc_code: {
      type: DataTypes.STRING(20),
      allowNull: false
    },
    status: {
      type: DataTypes.ENUM('ACTIVE', 'INACTIVE'),
      allowNull: false,
      defaultValue: 'ACTIVE'
    },
    created_by: {
      type: DataTypes.INTEGER,
      allowNull: true,
      references: {
        model: 'User',
        key: 'id'
      }
    },
    updated_by: {
      type: DataTypes.INTEGER,
      allowNull: true,
      references: {
        model: 'User',
        key: 'id'
      }
    }
  }, {
    tableName: 'company_bank_detail',
    indexes: [
      { fields: ['company_id'] },
      { fields: ['status'] },
      { unique: true, fields: ['company_id', 'account_no'] }
    ]
  });

  CompanyBankDetail.associate = function(models) {
    CompanyBankDetail.belongsTo(models.Company, { foreignKey: 'company_id', as: 'company' });
  };

  return CompanyBankDetail;
};

