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

label: {
        type: DataTypes.TEXT,
      
      

      },

quantity: {
        type: DataTypes.DECIMAL,
      
      

      },

unit_price: {
        type: DataTypes.DECIMAL,
      
      

      },

discount_rate: {
        type: DataTypes.DECIMAL,
      
      

      },

tax_rate: {
        type: DataTypes.DECIMAL,
      
      

      },

line_total: {
        type: DataTypes.DECIMAL,
      
      

      },

sort_order: {
        type: DataTypes.INTEGER,
      
      

      },

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

  quote_items.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.quote_items.belongsTo(db.quotes, {
      as: 'quote',
      foreignKey: {
        name: 'quoteId',
      },
      constraints: false,
    });

    db.quote_items.belongsTo(db.products, {
      as: 'product',
      foreignKey: {
        name: 'productId',
      },
      constraints: false,
    });




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

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



  return quote_items;
};


