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

const ClubFeature = sequelize.define('ClubFeature', {
  id: {
    type: DataTypes.INTEGER.UNSIGNED,
    primaryKey: true,
    autoIncrement: true,
    comment: '클럽-기능 연결 고유 식별자'
  },
  clubId: {
    type: DataTypes.INTEGER.UNSIGNED,
    allowNull: false,
    references: {
      model: 'Clubs',
      key: 'id'
    },
    comment: '클럽 ID'
  },
  featureId: {
    type: DataTypes.INTEGER.UNSIGNED,
    allowNull: false,
    references: {
      model: 'Features',
      key: 'id'
    },
    comment: '기능 ID'
  },
  enabled: {
    type: DataTypes.BOOLEAN,
    allowNull: false,
    defaultValue: true,
    comment: '기능 활성화 여부'
  },
  expiryDate: {
    type: DataTypes.DATE,
    allowNull: true,
    comment: '기능 만료일'
  },
  createdAt: {
    type: DataTypes.DATE,
    allowNull: false,
    comment: '생성일'
  },
  updatedAt: {
    type: DataTypes.DATE,
    allowNull: false,
    comment: '수정일'
  }
}, {
  tableName: 'ClubFeatures',
  comment: '클럽별 활성화된 기능 정보를 저장하는 테이블',
  timestamps: true
});

ClubFeature.associate = (models) => {
  ClubFeature.belongsTo(models.Club, { foreignKey: 'clubId' });
  ClubFeature.belongsTo(models.Feature, { foreignKey: 'featureId' });
};

module.exports = ClubFeature;
