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

const TournamentPairing = sequelize.define('TournamentPairing', {
    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'
    },
    classId: {
        type: DataTypes.INTEGER,
        allowNull: false,
        references: {
            model: TournamentClass,
            key: 'id'
        },
        onDelete: 'CASCADE',
        onUpdate: 'CASCADE'
    },
    groupId: {
        type: DataTypes.INTEGER,
        allowNull: true
    },
    // Player 1: entweder Mitglied oder externer Teilnehmer
    member1Id: {
        type: DataTypes.INTEGER,
        allowNull: true
    },
    external1Id: {
        type: DataTypes.INTEGER,
        allowNull: true
    },
    // Player 2: entweder Mitglied oder externer Teilnehmer
    member2Id: {
        type: DataTypes.INTEGER,
        allowNull: true
    },
    external2Id: {
        type: DataTypes.INTEGER,
        allowNull: true
    },
    seeded: {
        type: DataTypes.BOOLEAN,
        allowNull: false,
        defaultValue: false
    }
}, {
    underscored: true,
    tableName: 'tournament_pairing',
    timestamps: true
});

export default TournamentPairing;





