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

quantity: {
        type: DataTypes.INTEGER,
      
      

      },

coins_spent: {
        type: DataTypes.DECIMAL,
      
      

      },

fulfillment_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"requested",


"approved",


"rejected",


"fulfilled",


"cancelled"

        ],

      },

requested_at: {
        type: DataTypes.DATE,
      
      

      },

fulfilled_at: {
        type: DataTypes.DATE,
      
      

      },

fulfillment_note: {
        type: DataTypes.TEXT,
      
      

      },

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

  reward_redemptions.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.reward_redemptions.belongsTo(db.reward_catalog_items, {
      as: 'reward_catalog_item',
      foreignKey: {
        name: 'reward_catalog_itemId',
      },
      constraints: false,
    });

    db.reward_redemptions.belongsTo(db.organizations, {
      as: 'organization',
      foreignKey: {
        name: 'organizationId',
      },
      constraints: false,
    });

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




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

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



  return reward_redemptions;
};


