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

code: {
        type: DataTypes.TEXT,
      
      

      },

discount_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"percentage",


"fixed_amount",


"free_shipping"

        ],

      },

value: {
        type: DataTypes.DECIMAL,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"active",


"disabled",


"expired"

        ],

      },

starts_at: {
        type: DataTypes.DATE,
      
      

      },

ends_at: {
        type: DataTypes.DATE,
      
      

      },

usage_limit: {
        type: DataTypes.INTEGER,
      
      

      },

used_count: {
        type: DataTypes.INTEGER,
      
      

      },

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

  discount_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.discount_codes.belongsTo(db.stores, {
      as: 'store',
      foreignKey: {
        name: 'storeId',
      },
      constraints: false,
    });

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




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

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



  return discount_codes;
};


