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

min_participants: {
        type: DataTypes.INTEGER,
      
      

      },

max_participants: {
        type: DataTypes.INTEGER,
      
      

      },

price_amount: {
        type: DataTypes.DECIMAL,
      
      

      },

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

      },

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

      },

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

  price_rules.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.price_rules.belongsTo(db.price_lists, {
      as: 'price_list',
      foreignKey: {
        name: 'price_listId',
      },
      constraints: false,
    });

    db.price_rules.belongsTo(db.service_types, {
      as: 'service_type',
      foreignKey: {
        name: 'service_typeId',
      },
      constraints: false,
    });

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




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

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



  return price_rules;
};


