const { DataTypes } = require('sequelize'); const { sequelize } = require('../config/database'); const Event = sequelize.define('Event', { id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true }, clubId: { type: DataTypes.INTEGER, allowNull: false, references: { model: 'Clubs', key: 'id' } }, title: { type: DataTypes.STRING, allowNull: false }, description: { type: DataTypes.TEXT, allowNull: true }, eventType: { type: DataTypes.ENUM('정기전', '번개', '연습', '교류전', '이벤트', '기타'), allowNull: false, defaultValue: '정기전' }, startDate: { type: DataTypes.DATE, allowNull: false }, endDate: { type: DataTypes.DATE, allowNull: true }, location: { type: DataTypes.STRING, allowNull: true }, gameCount: { type: DataTypes.INTEGER, allowNull: false, defaultValue: 3 }, participantFee: { type: DataTypes.DECIMAL(10, 2), allowNull: false, defaultValue: 0 }, maxParticipants: { type: DataTypes.INTEGER, allowNull: false, defaultValue: 0 }, registrationDeadline: { type: DataTypes.DATE, allowNull: true }, participantCount: { type: DataTypes.INTEGER, allowNull: false, defaultValue: 0 }, status: { type: DataTypes.ENUM('준비', '활성', '완료', '취소', '삭제'), allowNull: false, defaultValue: '활성' }, createdAt: { type: DataTypes.DATE, allowNull: false }, updatedAt: { type: DataTypes.DATE, allowNull: false } }, { tableName: 'Events', timestamps: true }); // 관계 설정 Event.associate = (models) => { Event.belongsTo(models.Club, { foreignKey: 'clubId', as: 'club' }); Event.hasMany(models.EventParticipant, { foreignKey: 'eventId', as: 'participants' }); Event.hasMany(models.EventScore, { foreignKey: 'eventId', as: 'scores' }); }; module.exports = Event;