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'
    },
}, {
    underscored: true,
    tableName: 'club_team',
    timestamps: true,
});

export default ClubTeam;
