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

const TournamentClass = sequelize.define('TournamentClass', {
    id: {
        type: DataTypes.INTEGER,
        primaryKey: true,
        autoIncrement: true,
        allowNull: false
    },
    tournamentId: {
        type: DataTypes.INTEGER,
        allowNull: false,
        references: {
            model: Tournament,
            key: 'id'
        },
        onDelete: 'CASCADE',
        onUpdate: 'CASCADE'
    },
    name: {
        type: DataTypes.STRING,
        allowNull: false
    },
    sortOrder: {
        type: DataTypes.INTEGER,
        allowNull: false,
        defaultValue: 0
    },
    isDoubles: {
        type: DataTypes.BOOLEAN,
        allowNull: false,
        defaultValue: false
    },
    gender: {
        type: DataTypes.ENUM('male', 'female', 'mixed'),
        allowNull: true,
        defaultValue: null
    },
    minBirthYear: {
        type: DataTypes.INTEGER,
        allowNull: true,
        defaultValue: null,
        field: 'min_birth_year',
        comment: 'Geboren im Jahr X oder später (>=)'
    },
    maxBirthYear: {
        type: DataTypes.INTEGER,
        allowNull: true,
        defaultValue: null,
        field: 'max_birth_year',
        comment: 'Geboren im Jahr X oder früher (<=); für Altersklassen 12/10'
    }
}, {
    underscored: true,
    tableName: 'tournament_class',
    timestamps: true
});

export default TournamentClass;

