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

const TrainingCancellation = sequelize.define('TrainingCancellation', {
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true,
    allowNull: false,
  },
  clubId: {
    type: DataTypes.INTEGER,
    allowNull: false,
    references: {
      model: Club,
      key: 'id',
    },
    onDelete: 'CASCADE',
  },
  startDate: {
    type: DataTypes.DATEONLY,
    allowNull: false,
    field: 'start_date',
  },
  endDate: {
    type: DataTypes.DATEONLY,
    allowNull: false,
    field: 'end_date',
  },
  date: {
    type: DataTypes.DATEONLY,
    allowNull: true,
  },
  reason: {
    type: DataTypes.STRING(255),
    allowNull: true,
  },
  trainingGroupIds: {
    type: DataTypes.JSON,
    allowNull: true,
    field: 'training_group_ids',
  },
}, {
  tableName: 'training_cancellations',
  underscored: true,
  timestamps: true,
  indexes: [
    {
      unique: true,
      fields: ['club_id', 'start_date', 'end_date'],
    },
  ],
});

export default TrainingCancellation;
