import { DataTypes } from 'sequelize';
import sequelize from '../config/config.js';

const UserMaster = sequelize.define('UserMaster', {
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true
  },
  role_name: {
    type: DataTypes.STRING(50),
    allowNull: false,
    unique: true,
    comment: 'Role name like SUPER_ADMIN, CLIENT_ADMIN, etc.'
  },
  role_display_name: {
    type: DataTypes.STRING(100),
    allowNull: false,
    comment: 'Display name for the role like "Super Administrator"'
  },
  description: {
    type: DataTypes.TEXT,
    allowNull: true,
    comment: 'Description of what this role can do'
  },
  permissions: {
    type: DataTypes.JSON,
    allowNull: true,
    comment: 'JSON object containing permissions for this role'
  },
  is_active: {
    type: DataTypes.BOOLEAN,
    allowNull: false,
    defaultValue: true,
    comment: 'Whether this role is active'
  },
  created_by: {
    type: DataTypes.INTEGER,
    allowNull: true,
    comment: 'User ID who created this role'
  },
  sort_order: {
    type: DataTypes.INTEGER,
    allowNull: false,
    defaultValue: 0,
    comment: 'Order in which roles appear in UI'
  }
}, {
  tableName: 'user_master',
  timestamps: true,
  indexes: [
    {
      unique: true,
      fields: ['role_name']
    },
    {
      fields: ['is_active']
    }
  ]
});

export default UserMaster;
