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

code: {
        type: DataTypes.TEXT,
      
      

      },

name: {
        type: DataTypes.TEXT,
      
      

      },

description: {
        type: DataTypes.TEXT,
      
      

      },

discount_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"percent",


"amount"

        ],

      },

discount_value: {
        type: DataTypes.DECIMAL,
      
      

      },

minimum_order_amount: {
        type: DataTypes.DECIMAL,
      
      

      },

usage_limit_total: {
        type: DataTypes.INTEGER,
      
      

      },

usage_limit_per_user: {
        type: DataTypes.INTEGER,
      
      

      },

starts_at: {
        type: DataTypes.DATE,
      
      

      },

ends_at: {
        type: DataTypes.DATE,
      
      

      },

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

      },

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

  promo_codes.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.promo_codes.belongsTo(db.users, {
      as: 'createdBy',
    });

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



  return promo_codes;
};


