const { DataTypes } = require('sequelize'); const { sequelize } = require('../config/database'); const Club = sequelize.define('Club', { id: { type: DataTypes.INTEGER.UNSIGNED, primaryKey: true, autoIncrement: true }, name: { type: DataTypes.STRING, allowNull: false }, description: { type: DataTypes.TEXT, allowNull: true }, ownerId: { type: DataTypes.INTEGER.UNSIGNED, allowNull: false, references: { model: 'Users', key: 'id' } }, location: { type: DataTypes.STRING, allowNull: true }, contact: { type: DataTypes.STRING, allowNull: true }, status: { type: DataTypes.ENUM('active', 'inactive', 'suspended'), allowNull: false, defaultValue: 'active' }, memberCount: { type: DataTypes.INTEGER, allowNull: false, defaultValue: 0 }, createdAt: { type: DataTypes.DATE, allowNull: false }, updatedAt: { type: DataTypes.DATE, allowNull: false } }, { tableName: 'Clubs', timestamps: true }); Club.associate = (models) => { Club.hasMany(models.ClubFeature, { foreignKey: 'clubId' }); Club.hasMany(models.ClubSubscription, { foreignKey: 'clubId' }); Club.belongsTo(models.User, { foreignKey: 'ownerId', as: 'owner' }); Club.belongsToMany(models.Feature, { through: models.ClubFeature, foreignKey: 'clubId', }); Club.belongsToMany(models.SubscriptionPlan, { through: models.ClubSubscription, foreignKey: 'clubId', otherKey: 'planId', }); Club.hasMany(models.ClubSubscription, { foreignKey: 'clubId' }); Club.belongsToMany(models.Feature, { through: models.ClubFeature, foreignKey: 'clubId', }); }; module.exports = Club;