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

const ClubTeamMember = sequelize.define('ClubTeamMember', {
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true,
    allowNull: false,
  },
  clubTeamId: {
    type: DataTypes.INTEGER,
    allowNull: false,
    field: 'club_team_id',
  },
  memberId: {
    type: DataTypes.INTEGER,
    allowNull: false,
    field: 'member_id',
  },
  lineupHalf: {
    type: DataTypes.ENUM('first_half', 'second_half'),
    allowNull: false,
    defaultValue: 'first_half',
    field: 'lineup_half',
  },
  position: {
    type: DataTypes.INTEGER,
    allowNull: false,
  },
}, {
  underscored: true,
  tableName: 'club_team_member',
  timestamps: true,
  indexes: [
    {
      unique: true,
      fields: ['club_team_id', 'lineup_half', 'member_id'],
    },
    {
      unique: true,
      fields: ['club_team_id', 'lineup_half', 'position'],
    }
  ]
});

export default ClubTeamMember;
