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

program_name: {
        type: DataTypes.TEXT,
      
      

      },

earning_method: {
        type: DataTypes.ENUM,
      
      

        values: [

"amount_spent",


"per_item"

        ],

      },

earn_rate: {
        type: DataTypes.DECIMAL,
      
      

      },

redeem_value: {
        type: DataTypes.DECIMAL,
      
      

      },

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

      },

starts_at: {
        type: DataTypes.DATE,
      
      

      },

ends_at: {
        type: DataTypes.DATE,
      
      

      },

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

  loyalty_programs.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.loyalty_programs.belongsTo(db.organizations, {
      as: 'organizations',
      foreignKey: {
        name: 'organizationsId',
      },
      constraints: false,
    });




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

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



  return loyalty_programs;
};


