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

quantity: {
        type: DataTypes.INTEGER,
      
      

      },

unit_price: {
        type: DataTypes.DECIMAL,
      
      

      },

line_total: {
        type: DataTypes.DECIMAL,
      
      

      },

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

  sales_transaction_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.sales_transaction_lines.belongsTo(db.sales_transactions, {
      as: 'sales_transaction',
      foreignKey: {
        name: 'sales_transactionId',
      },
      constraints: false,
    });

    db.sales_transaction_lines.belongsTo(db.store_products, {
      as: 'store_product',
      foreignKey: {
        name: 'store_productId',
      },
      constraints: false,
    });




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

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



  return sales_transaction_lines;
};


