/**
 * 权限模型
 * @file Permission.js
 * @description 权限定义模型
 */

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

const Permission = sequelize.define('Permission', {
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true,
    comment: '权限ID'
  },
  permission_key: {
    type: DataTypes.STRING(100),
    allowNull: false,
    unique: true,
    comment: '权限标识'
  },
  permission_name: {
    type: DataTypes.STRING(100),
    allowNull: false,
    comment: '权限名称'
  },
  permission_desc: {
    type: DataTypes.TEXT,
    allowNull: true,
    comment: '权限描述'
  },
  module: {
    type: DataTypes.STRING(50),
    allowNull: false,
    comment: '所属模块'
  },
  action: {
    type: DataTypes.STRING(50),
    allowNull: false,
    comment: '操作类型'
  }
}, {
  tableName: 'permissions',
  timestamps: true,
  createdAt: 'created_at',
  updatedAt: 'updated_at',
  comment: '权限定义表',
  indexes: [
    {
      fields: ['module'],
      name: 'idx_module'
    },
    {
      fields: ['action'],
      name: 'idx_action'
    },
    {
      fields: ['permission_key'],
      name: 'idx_permission_key'
    }
  ]
});

module.exports = Permission;
