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

invoice_number: {
        type: DataTypes.TEXT,
      
      

      },

items: {
        type: DataTypes.TEXT,
      
      

      },

total_amount: {
        type: DataTypes.DECIMAL,
      
      

      },

tax: {
        type: DataTypes.DECIMAL,
      
      

      },

final_price: {
        type: DataTypes.DECIMAL,
      
      

      },

date: {
        type: DataTypes.DATE,
      
      

      },

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

  pharmacy_sales_invoices.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.pharmacy_sales_invoices.belongsTo(db.patients, {
      as: 'patient',
      foreignKey: {
        name: 'patientId',
      },
      constraints: false,
    });

    db.pharmacy_sales_invoices.belongsTo(db.users, {
      as: 'cashier',
      foreignKey: {
        name: 'cashierId',
      },
      constraints: false,
    });




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

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



  return pharmacy_sales_invoices;
};


