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

event_at: {
        type: DataTypes.DATE,
      
      

      },

latitude: {
        type: DataTypes.DECIMAL,
      
      

      },

longitude: {
        type: DataTypes.DECIMAL,
      
      

      },

speed_kph: {
        type: DataTypes.DECIMAL,
      
      

      },

heading: {
        type: DataTypes.TEXT,
      
      

      },

event_note: {
        type: DataTypes.TEXT,
      
      

      },

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

  truck_tracking_events.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.truck_tracking_events.belongsTo(db.trucks, {
      as: 'truck',
      foreignKey: {
        name: 'truckId',
      },
      constraints: false,
    });

    db.truck_tracking_events.belongsTo(db.medicine_dispatches, {
      as: 'medicine_dispatch',
      foreignKey: {
        name: 'medicine_dispatchId',
      },
      constraints: false,
    });




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

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



  return truck_tracking_events;
};


