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

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"joined",


"in_progress",


"completed",


"expired",


"cancelled"

        ],

      },

progress_value: {
        type: DataTypes.INTEGER,
      
      

      },

joined_at: {
        type: DataTypes.DATE,
      
      

      },

completed_at: {
        type: DataTypes.DATE,
      
      

      },

coins_awarded: {
        type: DataTypes.INTEGER,
      
      

      },

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

  user_challenges.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.user_challenges.belongsTo(db.users, {
      as: 'user',
      foreignKey: {
        name: 'userId',
      },
      constraints: false,
    });

    db.user_challenges.belongsTo(db.challenge_definitions, {
      as: 'challenge_definition',
      foreignKey: {
        name: 'challenge_definitionId',
      },
      constraints: false,
    });




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

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



  return user_challenges;
};


