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

const ClubUserRole = sequelize.define('ClubUserRole', {
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true,
    allowNull: false,
  },
  clubId: {
    type: DataTypes.INTEGER,
    allowNull: false,
    field: 'club_id',
  },
  userId: {
    type: DataTypes.INTEGER,
    allowNull: false,
    field: 'user_id',
  },
  clubRoleId: {
    type: DataTypes.INTEGER,
    allowNull: false,
    field: 'club_role_id',
  },
  isPrimary: {
    type: DataTypes.BOOLEAN,
    allowNull: false,
    defaultValue: false,
    field: 'is_primary',
  },
}, {
  tableName: 'club_user_roles',
  underscored: true,
  timestamps: true,
  indexes: [
    {
      unique: true,
      fields: ['club_id', 'user_id', 'club_role_id'],
    },
  ],
});

export default ClubUserRole;
