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

discount_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"percent",


"fixed_amount"

        ],

      },

discount_value: {
        type: DataTypes.DECIMAL,
      
      

      },

discount_amount: {
        type: DataTypes.DECIMAL,
      
      

      },

currency: {
        type: DataTypes.TEXT,
      
      

      },

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

  booking_discounts.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.booking_discounts.belongsTo(db.bookings, {
      as: 'booking',
      foreignKey: {
        name: 'bookingId',
      },
      constraints: false,
    });

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




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

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



  return booking_discounts;
};


