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

quantity: {
        type: DataTypes.INTEGER,
      
      

      },

unit_price: {
        type: DataTypes.DECIMAL,
      
      

      },

line_total: {
        type: DataTypes.DECIMAL,
      
      

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

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

  service_request_add_ons.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.service_request_add_ons.belongsTo(db.service_requests, {
      as: 'service_request',
      foreignKey: {
        name: 'service_requestId',
      },
      constraints: false,
    });

    db.service_request_add_ons.belongsTo(db.service_add_ons, {
      as: 'service_add_on',
      foreignKey: {
        name: 'service_add_onId',
      },
      constraints: false,
    });

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




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

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



  return service_request_add_ons;
};


