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

quantity: {
        type: DataTypes.DECIMAL,
      
      

      },

unit_price: {
        type: DataTypes.DECIMAL,
      
      

      },

vat_rate: {
        type: DataTypes.DECIMAL,
      
      

      },

vat_amount: {
        type: DataTypes.DECIMAL,
      
      

      },

refund_amount: {
        type: DataTypes.DECIMAL,
      
      

      },

condition_notes: {
        type: DataTypes.TEXT,
      
      

      },

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

  return_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.return_items.belongsTo(db.returns, {
      as: 'return',
      foreignKey: {
        name: 'returnId',
      },
      constraints: false,
    });

    db.return_items.belongsTo(db.sale_items, {
      as: 'sale_item',
      foreignKey: {
        name: 'sale_itemId',
      },
      constraints: false,
    });

    db.return_items.belongsTo(db.products, {
      as: 'product',
      foreignKey: {
        name: 'productId',
      },
      constraints: false,
    });

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




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

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



  return return_items;
};


