const { DataTypes } = require('sequelize');
const { sequelize } = require('../config/database');

const EventTeam = sequelize.define('EventTeam', {
  id: {
    type: DataTypes.INTEGER.UNSIGNED,
    primaryKey: true,
    autoIncrement: true,
    comment: '이벤트 팀 고유 식별자',
  },
  eventId: {
    type: DataTypes.INTEGER.UNSIGNED,
    allowNull: false,
    comment: '이벤트 ID',
  },
  teamNumber: {
    type: DataTypes.INTEGER.UNSIGNED,
    allowNull: false,
    comment: '팀 번호',
  },
  name: {
    type: DataTypes.STRING,
    allowNull: true,
    comment: '팀명',
  },
  handicap: {
    type: DataTypes.INTEGER,
    allowNull: true,
    comment: '팀 핸디캡',
  },
}, {
  tableName: 'EventTeams',
  comment: '이벤트별 팀 정보를 저장하는 테이블',
  timestamps: true,
});

EventTeam.associate = (models) => {
  EventTeam.belongsTo(models.Event, { foreignKey: 'eventId' });
  EventTeam.hasMany(models.EventParticipant, { foreignKey: 'teamId' });
  EventTeam.hasMany(models.EventTeamMember, { foreignKey: 'eventTeamId' });
};

module.exports = EventTeam;