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

const ClubRole = sequelize.define('ClubRole', {
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true,
    allowNull: false,
  },
  clubId: {
    type: DataTypes.INTEGER,
    allowNull: false,
    field: 'club_id',
  },
  roleKey: {
    type: DataTypes.STRING(64),
    allowNull: false,
    field: 'role_key',
  },
  name: {
    type: DataTypes.STRING(120),
    allowNull: false,
  },
  description: {
    type: DataTypes.TEXT,
    allowNull: true,
  },
  permissions: {
    type: DataTypes.JSON,
    allowNull: false,
    defaultValue: {},
  },
  isSystemRole: {
    type: DataTypes.BOOLEAN,
    allowNull: false,
    defaultValue: false,
    field: 'is_system_role',
  },
  sortOrder: {
    type: DataTypes.INTEGER,
    allowNull: false,
    defaultValue: 0,
    field: 'sort_order',
  },
}, {
  tableName: 'club_roles',
  underscored: true,
  timestamps: true,
  indexes: [
    {
      unique: true,
      fields: ['club_id', 'role_key'],
    },
  ],
});

export default ClubRole;
