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

const UserClub = sequelize.define('UserClub', {
  userId: {
    type: DataTypes.INTEGER,
    references: {
      model: User,
      key: 'id',
    },
  },
  clubId: {
    type: DataTypes.INTEGER,
    references: {
      model: Club,
      key: 'id',
    },
  },  
  approved: {
    type: DataTypes.BOOLEAN,
    defaultValue: false,
  },
}, {
  underscored: true,
  tableName: 'user_club',
  timestamps: true
});

User.belongsToMany(Club, { through: UserClub, foreignKey: 'userId' });
Club.belongsToMany(User, { through: UserClub, foreignKey: 'clubId' });

export default UserClub;
