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

program_name: {
        type: DataTypes.TEXT,
      
      

      },

program_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"draft",


"active",


"inactive",


"ended"

        ],

      },

target_metric: {
        type: DataTypes.ENUM,
      
      

        values: [

"revenue",


"profit_estimate",


"orders_count",


"units_sold"

        ],

      },

target_value: {
        type: DataTypes.DECIMAL,
      
      

      },

reward_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"percentage",


"fixed_amount",


"gift"

        ],

      },

reward_rate: {
        type: DataTypes.DECIMAL,
      
      

      },

reward_amount: {
        type: DataTypes.DECIMAL,
      
      

      },

gift_description: {
        type: DataTypes.TEXT,
      
      

      },

starts_at: {
        type: DataTypes.DATE,
      
      

      },

ends_at: {
        type: DataTypes.DATE,
      
      

      },

terms: {
        type: DataTypes.TEXT,
      
      

      },

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

  bonus_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.bonus_programs.belongsTo(db.tenants, {
      as: 'tenant',
      foreignKey: {
        name: 'tenantId',
      },
      constraints: false,
    });

    db.bonus_programs.belongsTo(db.organizations, {
      as: 'organizations',
      foreignKey: {
        name: 'organizationsId',
      },
      constraints: false,
    });




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

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



  return bonus_programs;
};


