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

const TrainingTime = sequelize.define('TrainingTime', {
    id: {
        type: DataTypes.INTEGER,
        primaryKey: true,
        autoIncrement: true,
        allowNull: false,
    },
    trainingGroupId: {
        type: DataTypes.INTEGER,
        allowNull: false,
        references: {
            model: TrainingGroup,
            key: 'id',
        },
        onDelete: 'CASCADE',
    },
    weekday: {
        type: DataTypes.INTEGER,
        allowNull: false,
        comment: '0 = Sunday, 1 = Monday, ..., 6 = Saturday'
    },
    startTime: {
        type: DataTypes.TIME,
        allowNull: false,
    },
    endTime: {
        type: DataTypes.TIME,
        allowNull: false,
    },
    sortOrder: {
        type: DataTypes.INTEGER,
        allowNull: false,
        defaultValue: 0,
        comment: 'Order for displaying multiple times on the same weekday'
    }
}, {
    tableName: 'training_times',
    underscored: true,
    timestamps: true,
});

export default TrainingTime;

