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 Team = sequelize.define('Team', {
    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',
    },
    // Tabellenfelder
    matchesPlayed: {
        type: DataTypes.INTEGER,
        allowNull: false,
        defaultValue: 0,
    },
    matchesWon: {
        type: DataTypes.INTEGER,
        allowNull: false,
        defaultValue: 0,
    },
    matchesLost: {
        type: DataTypes.INTEGER,
        allowNull: false,
        defaultValue: 0,
    },
    matchesTied: {
        type: DataTypes.INTEGER,
        allowNull: false,
        defaultValue: 0,
    },
    setsWon: {
        type: DataTypes.INTEGER,
        allowNull: false,
        defaultValue: 0,
    },
    setsLost: {
        type: DataTypes.INTEGER,
        allowNull: false,
        defaultValue: 0,
    },
    pointsWon: {
        type: DataTypes.INTEGER,
        allowNull: false,
        defaultValue: 0,
    },
    pointsLost: {
        type: DataTypes.INTEGER,
        allowNull: false,
        defaultValue: 0,
    },
    tablePoints: {
        type: DataTypes.INTEGER,
        allowNull: false,
        defaultValue: 0,
    },
    tablePointsWon: {
        type: DataTypes.INTEGER,
        allowNull: false,
        defaultValue: 0,
    },
    tablePointsLost: {
        type: DataTypes.INTEGER,
        allowNull: false,
        defaultValue: 0,
    },
}, {
    underscored: true,
    tableName: 'team',
    timestamps: true,
});

export default Team;
