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

referral_code: {
        type: DataTypes.TEXT,
      
      

      },

referred_email: {
        type: DataTypes.TEXT,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"INVITED",


"SIGNED_UP",


"REWARDED",


"CANCELLED"

        ],

      },

invited_at: {
        type: DataTypes.DATE,
      
      

      },

signed_up_at: {
        type: DataTypes.DATE,
      
      

      },

rewarded_at: {
        type: DataTypes.DATE,
      
      

      },

reward_doodlecoins: {
        type: DataTypes.INTEGER,
      
      

      },

note: {
        type: DataTypes.TEXT,
      
      

      },

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

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

    db.referrals.belongsTo(db.users, {
      as: 'referred_user',
      foreignKey: {
        name: 'referred_userId',
      },
      constraints: false,
    });




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

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



  return referrals;
};


