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,
      },

line_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"rental_charge",


"lease_charge",


"penalty",


"admin_fee",


"fuel_recovery",


"mileage_charge"

        ],

      },

description: {
        type: DataTypes.TEXT,
      
      

      },

quantity: {
        type: DataTypes.DECIMAL,
      
      

      },

rate: {
        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.vehicles, {
      as: 'vehicle',
      foreignKey: {
        name: 'vehicleId',
      },
      constraints: false,
    });

    db.invoice_lines.belongsTo(db.chart_of_accounts, {
      as: 'revenue_account',
      foreignKey: {
        name: 'revenue_accountId',
      },
      constraints: false,
    });

    db.invoice_lines.belongsTo(db.companies, {
      as: 'companies',
      foreignKey: {
        name: 'companiesId',
      },
      constraints: false,
    });




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

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



  return invoice_lines;
};


