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 weekly_challenges = sequelize.define(
    'weekly_challenges',
    {
      id: {
        type: DataTypes.UUID,
        defaultValue: DataTypes.UUIDV4,
        primaryKey: true,
      },

name: {
        type: DataTypes.TEXT,
      
      

      },

description: {
        type: DataTypes.TEXT,
      
      

      },

start_at: {
        type: DataTypes.DATE,
      
      

      },

end_at: {
        type: DataTypes.DATE,
      
      

      },

tasks_json: {
        type: DataTypes.TEXT,
      
      

      },

reward_points: {
        type: DataTypes.INTEGER,
      
      

      },

reward_badge_key: {
        type: DataTypes.TEXT,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"upcoming",


"active",


"ended"

        ],

      },

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

  weekly_challenges.associate = (db) => {


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































    db.weekly_challenges.hasMany(db.challenge_participations, {
      as: 'challenge_participations_challenge',
      foreignKey: {
          name: 'challengeId',
      },
      constraints: false,
    });














//end loop






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

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



  return weekly_challenges;
};


