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

name: {
        type: DataTypes.TEXT,
      
      

      },

vehicle_number: {
        type: DataTypes.TEXT,
      
      

      },

license_plate: {
        type: DataTypes.TEXT,
      
      

      },

vin: {
        type: DataTypes.TEXT,
      
      

      },

active: {
        type: DataTypes.BOOLEAN,
      
        allowNull: false,
        defaultValue: false,
      
      

      },

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

  vehicles.associate = (db) => {


/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity










    db.vehicles.hasMany(db.job_logs, {
      as: 'job_logs_vehicle',
      foreignKey: {
          name: 'vehicleId',
      },
      constraints: false,
    });






//end loop






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

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



  return vehicles;
};


