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

item_name: {
        type: DataTypes.TEXT,
      
      

      },

item_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"gift_card",


"swag",


"perk",


"pto"

        ],

      },

description: {
        type: DataTypes.TEXT,
      
      

      },

cost_coins: {
        type: DataTypes.DECIMAL,
      
      

      },

inventory_quantity: {
        type: DataTypes.INTEGER,
      
      

      },

is_active: {
        type: DataTypes.BOOLEAN,
      
        allowNull: false,
        defaultValue: false,
      
      

      },

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

  reward_catalog_items.associate = (db) => {


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

































    db.reward_catalog_items.hasMany(db.reward_redemptions, {
      as: 'reward_redemptions_reward_catalog_item',
      foreignKey: {
          name: 'reward_catalog_itemId',
      },
      constraints: false,
    });















//end loop



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



    db.reward_catalog_items.hasMany(db.file, {
      as: 'item_images',
      foreignKey: 'belongsToId',
      constraints: false,
      scope: {
        belongsTo: db.reward_catalog_items.getTableName(),
        belongsToColumn: 'item_images',
      },
    });


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

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



  return reward_catalog_items;
};


