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

quantity: {
        type: DataTypes.INTEGER,
      
      

      },

dosage_instructions: {
        type: DataTypes.TEXT,
      
      

      },

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

  dispatch_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.dispatch_items.belongsTo(db.medicine_dispatches, {
      as: 'medicine_dispatch',
      foreignKey: {
        name: 'medicine_dispatchId',
      },
      constraints: false,
    });

    db.dispatch_items.belongsTo(db.medicines, {
      as: 'medicine',
      foreignKey: {
        name: 'medicineId',
      },
      constraints: false,
    });




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

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



  return dispatch_items;
};


