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

code: {
        type: DataTypes.TEXT,

      },

type: {
        type: DataTypes.ENUM,

        values: [

"amount_off",

"percent_off"

        ],

      },

value: {
        type: DataTypes.DECIMAL,

      },

currency: {
        type: DataTypes.TEXT,

      },

starts_at: {
        type: DataTypes.DATE,

      },

ends_at: {
        type: DataTypes.DATE,

      },

max_redemptions: {
        type: DataTypes.INTEGER,

      },

times_redeemed: {
        type: DataTypes.INTEGER,

      },

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

  coupons.associate = (db) => {

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

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

  return coupons;
};

