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

name: {
        type: DataTypes.TEXT,
      
      

      },

quantity: {
        type: DataTypes.INTEGER,
      
      

      },

unit_price: {
        type: DataTypes.DECIMAL,
      
      

      },

total_price: {
        type: DataTypes.DECIMAL,
      
      

      },

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

  surgery_consumables.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.surgery_consumables.belongsTo(db.surgery_cases, {
      as: 'surgery_case',
      foreignKey: {
        name: 'surgery_caseId',
      },
      constraints: false,
    });




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

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



  return surgery_consumables;
};


