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,
    primaryKey: true,
    references: {
      model: User,
      key: 'id',
    },
  },
  clubId: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    references: {
      model: Club,
      key: 'id',
    },
  },  
  approved: {
    type: DataTypes.BOOLEAN,
    defaultValue: false,
  },
  role: {
    type: DataTypes.STRING(50),
    defaultValue: 'member',
    allowNull: false,
    comment: 'User role: admin, trainer, team_manager, member'
  },
  permissions: {
    type: DataTypes.JSON,
    allowNull: true,
    comment: 'Specific permissions: {diary: {read: true, write: true}, members: {...}, ...}'
  },
  isOwner: {
    type: DataTypes.BOOLEAN,
    defaultValue: false,
    allowNull: false,
    comment: 'True if user created the club'
  }
}, {
  underscored: true,
  tableName: 'user_club',
  timestamps: true
});

export default UserClub;
