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

work_date: {
        type: DataTypes.DATE,
      
      

      },

hours_conducted: {
        type: DataTypes.DECIMAL,
      
      

      },

client_paid: {
        type: DataTypes.DECIMAL,
      
      

      },

odometer_start: {
        type: DataTypes.INTEGER,
      
      

      },

odometer_end: {
        type: DataTypes.INTEGER,
      
      

      },

job_address: {
        type: DataTypes.TEXT,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"submitted",


"approved",


"needs_correction",


"paid"

        ],

      },

notes_to_admin: {
        type: DataTypes.TEXT,
      
      

      },

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

  job_logs.associate = (db) => {


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











    db.job_logs.hasMany(db.job_chemical_usages, {
      as: 'job_chemical_usages_job_log',
      foreignKey: {
          name: 'job_logId',
      },
      constraints: false,
    });





//end loop



    db.job_logs.belongsTo(db.users, {
      as: 'employee',
      foreignKey: {
        name: 'employeeId',
      },
      constraints: false,
    });

    db.job_logs.belongsTo(db.customers, {
      as: 'customer',
      foreignKey: {
        name: 'customerId',
      },
      constraints: false,
    });

    db.job_logs.belongsTo(db.pay_types, {
      as: 'pay_type',
      foreignKey: {
        name: 'pay_typeId',
      },
      constraints: false,
    });

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

    db.job_logs.belongsTo(db.workers_comp_classes, {
      as: 'workersCompClass',
      foreignKey: {
        name: 'workersCompClassId',
      },
      constraints: false,
    });




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

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



  return job_logs;
};