const config = require('../../config');
const providers = config.providers;
const crypto = require('crypto');
const bcrypt = require('bcrypt');
const moment = require('moment');

module.exports = function(sequelize, DataTypes) {
  const challenge_participants = sequelize.define(
    'challenge_participants',
    {
      id: {
        type: DataTypes.UUID,
        defaultValue: DataTypes.UUIDV4,
        primaryKey: true,
      },

participant_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"user",


"team"

        ],

      },

current_value: {
        type: DataTypes.DECIMAL,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"active",


"completed",


"disqualified"

        ],

      },

rank_position: {
        type: DataTypes.INTEGER,
      
      

      },

      importHash: {
        type: DataTypes.STRING(255),
        allowNull: true,
        unique: true,
      },
    },
    {
      timestamps: true,
      paranoid: true,
      freezeTableName: true,
    },
  );

  challenge_participants.associate = (db) => {


/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity















































//end loop



    db.challenge_participants.belongsTo(db.challenges, {
      as: 'challenge',
      foreignKey: {
        name: 'challengeId',
      },
      constraints: false,
    });

    db.challenge_participants.belongsTo(db.users, {
      as: 'user',
      foreignKey: {
        name: 'userId',
      },
      constraints: false,
    });

    db.challenge_participants.belongsTo(db.teams, {
      as: 'team',
      foreignKey: {
        name: 'teamId',
      },
      constraints: false,
    });

    db.challenge_participants.belongsTo(db.organizations, {
      as: 'organizations',
      foreignKey: {
        name: 'organizationsId',
      },
      constraints: false,
    });




    db.challenge_participants.belongsTo(db.users, {
      as: 'createdBy',
    });

    db.challenge_participants.belongsTo(db.users, {
      as: 'updatedBy',
    });
  };



  return challenge_participants;
};


