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

quantity_received: {
        type: DataTypes.DECIMAL,
      
      

      },

lot_number: {
        type: DataTypes.TEXT,
      
      

      },

inspection_required: {
        type: DataTypes.ENUM,
      
      

        values: [

"yes",


"no"

        ],

      },

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

  receipt_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.receipt_lines.belongsTo(db.receipts, {
      as: 'receipt',
      foreignKey: {
        name: 'receiptId',
      },
      constraints: false,
    });

    db.receipt_lines.belongsTo(db.purchase_order_lines, {
      as: 'purchase_order_line',
      foreignKey: {
        name: 'purchase_order_lineId',
      },
      constraints: false,
    });

    db.receipt_lines.belongsTo(db.items, {
      as: 'item',
      foreignKey: {
        name: 'itemId',
      },
      constraints: false,
    });

    db.receipt_lines.belongsTo(db.locations, {
      as: 'to_location',
      foreignKey: {
        name: 'to_locationId',
      },
      constraints: false,
    });




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

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



  return receipt_lines;
};


