/**
 * 角色菜单权限关联模型
 * @file RoleMenuPermission.js
 * @description 角色和菜单权限的多对多关联表
 */

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

const RoleMenuPermission = sequelize.define('RoleMenuPermission', {
  role_id: {
    type: DataTypes.INTEGER,
    allowNull: false,
    primaryKey: true,
    comment: '角色ID',
    references: {
      model: 'roles',
      key: 'id'
    }
  },
  menu_permission_id: {
    type: DataTypes.INTEGER,
    allowNull: false,
    primaryKey: true,
    comment: '菜单权限ID',
    references: {
      model: 'menu_permissions',
      key: 'id'
    }
  },
  created_at: {
    type: DataTypes.DATE,
    allowNull: false,
    defaultValue: DataTypes.NOW,
    comment: '创建时间'
  }
}, {
  tableName: 'RoleMenuPermissions',
  timestamps: false, // 手动管理时间戳
  comment: '角色菜单权限关联表',
  indexes: [
    {
      fields: ['role_id'],
      name: 'idx_role_id'
    },
    {
      fields: ['menu_permission_id'],
      name: 'idx_menu_permission_id'
    }
  ]
});

module.exports = RoleMenuPermission;
