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

const League = sequelize.define('League', {
    id: {
        type: DataTypes.INTEGER,
        primaryKey: true,
        autoIncrement: true,
        allowNull: false,
    },
    name: {
        type: DataTypes.STRING,
        allowNull: false,
    },
    seasonId: {
        type: DataTypes.INTEGER,
        allowNull: false,
        references: {
            model: Season,
            key: 'id',
        },
        onDelete: 'CASCADE',
        onUpdate: 'CASCADE',
    },
    clubId: {
        type: DataTypes.INTEGER,
        allowNull: false,
        references: {
            model: Club,
            key: 'id',
        },
        onDelete: 'CASCADE',
        onUpdate: 'CASCADE',
    },
    myTischtennisGroupId: {
        type: DataTypes.STRING,
        allowNull: true,
        comment: 'Group ID from myTischtennis (e.g. 504417)',
        field: 'my_tischtennis_group_id'
    },
    association: {
        type: DataTypes.STRING,
        allowNull: true,
        comment: 'Association/Verband (e.g. HeTTV)',
    },
    groupname: {
        type: DataTypes.STRING,
        allowNull: true,
        comment: 'Group name for URL (e.g. 1.Kreisklasse)',
    },
}, {
    underscored: true,
    tableName: 'league',
    timestamps: true,
});

export default League;
