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

const ClubVenue = sequelize.define('ClubVenue', {
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true,
    allowNull: false,
  },
  clubId: {
    type: DataTypes.INTEGER,
    allowNull: false,
    references: {
      model: Club,
      key: 'id',
    },
    onDelete: 'CASCADE',
    field: 'club_id',
  },
  name: {
    type: DataTypes.STRING(255),
    allowNull: false,
  },
  address: {
    type: DataTypes.STRING(255),
    allowNull: true,
  },
  zip: {
    type: DataTypes.STRING(32),
    allowNull: true,
  },
  city: {
    type: DataTypes.STRING(255),
    allowNull: true,
  },
  sortOrder: {
    type: DataTypes.INTEGER,
    allowNull: false,
    defaultValue: 0,
    field: 'sort_order',
  },
}, {
  tableName: 'club_venue',
  underscored: true,
  timestamps: true,
  indexes: [
    { fields: ['club_id', 'sort_order'] },
    { fields: ['club_id', 'name'] },
  ],
});

export default ClubVenue;
