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

const FriendlyMatch = sequelize.define('FriendlyMatch', {
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true,
    allowNull: false,
  },
  clubId: {
    type: DataTypes.INTEGER,
    allowNull: false,
    field: 'club_id',
  },
  date: {
    type: DataTypes.DATEONLY,
    allowNull: false,
  },
  time: {
    type: DataTypes.TIME,
    allowNull: true,
  },
  homeTeamName: {
    type: DataTypes.STRING(255),
    allowNull: false,
    field: 'home_team_name',
  },
  guestTeamName: {
    type: DataTypes.STRING(255),
    allowNull: false,
    field: 'guest_team_name',
  },
  locationName: {
    type: DataTypes.STRING(255),
    allowNull: true,
    field: 'location_name',
  },
  locationAddress: {
    type: DataTypes.STRING(255),
    allowNull: true,
    field: 'location_address',
  },
  locationCity: {
    type: DataTypes.STRING(255),
    allowNull: true,
    field: 'location_city',
  },
  locationZip: {
    type: DataTypes.STRING(32),
    allowNull: true,
    field: 'location_zip',
  },
  matchSystem: {
    type: DataTypes.STRING(120),
    allowNull: false,
    defaultValue: 'Braunschweiger System',
    field: 'match_system',
  },
  singlesCount: {
    type: DataTypes.INTEGER,
    allowNull: false,
    defaultValue: 12,
    field: 'singles_count',
  },
  doublesCount: {
    type: DataTypes.INTEGER,
    allowNull: false,
    defaultValue: 4,
    field: 'doubles_count',
  },
  winningSets: {
    type: DataTypes.INTEGER,
    allowNull: false,
    defaultValue: 3,
    field: 'winning_sets',
  },
  homeMatchPoints: {
    type: DataTypes.INTEGER,
    allowNull: false,
    defaultValue: 0,
    field: 'home_match_points',
  },
  guestMatchPoints: {
    type: DataTypes.INTEGER,
    allowNull: false,
    defaultValue: 0,
    field: 'guest_match_points',
  },
  isCompleted: {
    type: DataTypes.BOOLEAN,
    allowNull: false,
    defaultValue: false,
    field: 'is_completed',
  },
  homeParticipants: {
    type: DataTypes.JSON,
    allowNull: true,
    field: 'home_participants',
  },
  guestParticipants: {
    type: DataTypes.JSON,
    allowNull: true,
    field: 'guest_participants',
  },
  resultDetails: {
    type: DataTypes.JSON,
    allowNull: true,
    field: 'result_details',
  },
  playersReady: {
    type: DataTypes.JSON,
    allowNull: true,
    field: 'players_ready',
  },
  playersPlanned: {
    type: DataTypes.JSON,
    allowNull: true,
    field: 'players_planned',
  },
  playersPlayed: {
    type: DataTypes.JSON,
    allowNull: true,
    field: 'players_played',
  },
}, {
  tableName: 'friendly_match',
  underscored: true,
  timestamps: true,
});

export default FriendlyMatch;
