const { DataTypes } = require('sequelize');
const { sequelize } = require('../config/database');

const MenuPermission = sequelize.define('MenuPermission', {
  id: {
    type: DataTypes.INTEGER,
    autoIncrement: true,
    primaryKey: true,
    comment: '关联ID'
  },
  menu_id: {
    type: DataTypes.INTEGER,
    allowNull: false,
    comment: '菜单ID'
  },
  permission_id: {
    type: DataTypes.INTEGER,
    allowNull: false,
    comment: '权限ID'
  },
  required: {
    type: DataTypes.BOOLEAN,
    allowNull: false,
    defaultValue: true,
    comment: '是否必需权限'
  }
}, {
  tableName: 'menu_permissions',
  timestamps: true,
  underscored: true,
  indexes: [
    { 
      fields: ['menu_id', 'permission_id'], 
      unique: true,
      name: 'uk_menu_permission'
    },
    { fields: ['menu_id'] },
    { fields: ['permission_id'] }
  ]
});

module.exports = MenuPermission;

