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

const ClubTeam = sequelize.define('ClubTeam', {
    id: {
        type: DataTypes.INTEGER,
        primaryKey: true,
        autoIncrement: true,
        allowNull: false,
    },
    name: {
        type: DataTypes.STRING,
        allowNull: false,
    },
    clubId: {
        type: DataTypes.INTEGER,
        allowNull: false,
        references: {
            model: Club,
            key: 'id',
        },
        onDelete: 'CASCADE',
        onUpdate: 'CASCADE',
    },
    leagueId: {
        type: DataTypes.INTEGER,
        allowNull: true,
        references: {
            model: League,
            key: 'id',
        },
        onDelete: 'SET NULL',
        onUpdate: 'CASCADE',
    },
    seasonId: {
        type: DataTypes.INTEGER,
        allowNull: true,
        references: {
            model: Season,
            key: 'id',
        },
        onDelete: 'CASCADE',
        onUpdate: 'CASCADE',
    },
    myTischtennisTeamId: {
        type: DataTypes.STRING,
        allowNull: true,
        comment: 'Team ID from myTischtennis (e.g. 2995094)',
        field: 'my_tischtennis_team_id'
    },
    teamGender: {
        type: DataTypes.ENUM('open', 'female'),
        allowNull: false,
        defaultValue: 'open',
        field: 'team_gender'
    },
    teamAgeGroup: {
        type: DataTypes.ENUM('adult', 'J19', 'J17', 'J15', 'J13', 'J11'),
        allowNull: false,
        defaultValue: 'adult',
        field: 'team_age_group'
    },
    plannedLeagueName: {
        type: DataTypes.STRING(512),
        allowNull: true,
        field: 'planned_league_name',
        comment: 'Geplante Spielklasse (manuell, optional)'
    },
}, {
    underscored: true,
    tableName: 'club_team',
    timestamps: true,
});

export default ClubTeam;
