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

quantity_received: {
        type: DataTypes.INTEGER,
      
      

      },

quantity_rejected: {
        type: DataTypes.INTEGER,
      
      

      },

remarks: {
        type: DataTypes.TEXT,
      
      

      },

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

  grn_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.grn_lines.belongsTo(db.tenants, {
      as: 'tenant',
      foreignKey: {
        name: 'tenantId',
      },
      constraints: false,
    });

    db.grn_lines.belongsTo(db.goods_receipt_notes, {
      as: 'goods_receipt_note',
      foreignKey: {
        name: 'goods_receipt_noteId',
      },
      constraints: false,
    });

    db.grn_lines.belongsTo(db.po_lines, {
      as: 'po_line',
      foreignKey: {
        name: 'po_lineId',
      },
      constraints: false,
    });

    db.grn_lines.belongsTo(db.organizations, {
      as: 'organizations',
      foreignKey: {
        name: 'organizationsId',
      },
      constraints: false,
    });




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

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



  return grn_lines;
};


