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,
      
      

      },

discount_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"percent",


"fixed_amount"

        ],

      },

discount_value: {
        type: DataTypes.DECIMAL,
      
      

      },

currency: {
        type: DataTypes.TEXT,
      
      

      },

valid_from_at: {
        type: DataTypes.DATE,
      
      

      },

valid_to_at: {
        type: DataTypes.DATE,
      
      

      },

max_uses: {
        type: DataTypes.INTEGER,
      
      

      },

max_uses_per_guest: {
        type: DataTypes.INTEGER,
      
      

      },

min_nights: {
        type: DataTypes.INTEGER,
      
      

      },

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
























    db.promo_codes.hasMany(db.booking_discounts, {
      as: 'booking_discounts_promo_code',
      foreignKey: {
          name: 'promo_codeId',
      },
      constraints: false,
    });







//end loop



    db.promo_codes.belongsTo(db.hotels, {
      as: 'hotel',
      foreignKey: {
        name: 'hotelId',
      },
      constraints: false,
    });




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

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



  return promo_codes;
};


