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

type: {
        type: DataTypes.ENUM,
      
      

        values: [

"FREIGHT",


"FUEL_SURCHARGE",


"TOLL",


"WAITING",


"EXTRA_STOP",


"ADR_SURCHARGE",


"OTHER"

        ],

      },

description: {
        type: DataTypes.TEXT,
      
      

      },

quantity: {
        type: DataTypes.DECIMAL,
      
      

      },

unit_price: {
        type: DataTypes.DECIMAL,
      
      

      },

amount: {
        type: DataTypes.DECIMAL,
      
      

      },

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

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

    db.invoice_lines.belongsTo(db.trips, {
      as: 'trip',
      foreignKey: {
        name: 'tripId',
      },
      constraints: false,
    });

    db.invoice_lines.belongsTo(db.loads, {
      as: 'load',
      foreignKey: {
        name: 'loadId',
      },
      constraints: false,
    });

    db.invoice_lines.belongsTo(db.cost_items, {
      as: 'cost_item',
      foreignKey: {
        name: 'cost_itemId',
      },
      constraints: false,
    });




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

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



  return invoice_lines;
};


