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

description: {
        type: DataTypes.TEXT,
      
      

      },

quantity: {
        type: DataTypes.DECIMAL,
      
      

      },

unitPrice: {
        type: DataTypes.DECIMAL,
      
      

      },

lineTotal: {
        type: DataTypes.DECIMAL,
      
      

      },

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

  ar_invoice_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.ar_invoice_items.belongsTo(db.ar_invoices, {
      as: 'invoice',
      foreignKey: {
        name: 'invoiceId',
      },
      constraints: false,
    });




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

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



  return ar_invoice_items;
};


