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

sequence: {
        type: DataTypes.INTEGER,
      
      

      },

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

  trip_loads.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.trip_loads.belongsTo(db.trips, {
      as: 'trip',
      foreignKey: {
        name: 'tripId',
      },
      constraints: false,
    });

    db.trip_loads.belongsTo(db.loads, {
      as: 'load',
      foreignKey: {
        name: 'loadId',
      },
      constraints: false,
    });




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

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



  return trip_loads;
};


