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

const Match = sequelize.define('Match', {
    id: {
        type: DataTypes.INTEGER,
        primaryKey: true,
        autoIncrement: true,
        allowNull: false,
    },
    date: {
        type: DataTypes.DATE,
        allowNull: false,
    },
    time: {
        type: DataTypes.TIME,
        allowNull: true,
    },
    seasonId: {
        type: DataTypes.INTEGER,
        references: {
            model: Season,
            key: 'id',
        },
        allowNull: false,
    },
    locationId: {
        type: DataTypes.INTEGER,
        references: {
            model: Location,
            key: 'id',
        },
        allowNull: false,
    },
    homeTeamId: {
        type: DataTypes.INTEGER,
        references: {
            model: Team,
            key: 'id',
        },
        allowNull: false,
    },
    guestTeamId: {
        type: DataTypes.INTEGER,
        references: {
            model: Team,
            key: 'id',
        },
        allowNull: false,
    },
    leagueId: {
        type: DataTypes.INTEGER,
        references: {
            model: League,
            key: 'id',
        },
        allowNull: false,
    },
    clubId: {
        type: DataTypes.INTEGER,
        references: {
            model: Club,
            key: 'id',
        },
        allowNull: false,
    },
}, {
    underscored: true,
    tableName: 'match',
    timestamps: true,
});

export default Match;
