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

item_description: {
        type: DataTypes.TEXT,
      
      

      },

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,
    },
  );

  order_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.order_items.belongsTo(db.repair_orders, {
      as: 'repair_order',
      foreignKey: {
        name: 'repair_orderId',
      },
      constraints: false,
    });

    db.order_items.belongsTo(db.repair_services, {
      as: 'repair_service',
      foreignKey: {
        name: 'repair_serviceId',
      },
      constraints: false,
    });




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

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



  return order_items;
};


