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

type: {
        type: DataTypes.ENUM,
      
      

        values: [

"FINE",


"ACCIDENT",


"TACHO_VIOLATION",


"DISCIPLINARY",


"VEHICLE_DAMAGE",


"OTHER"

        ],

      },

occurred_at: {
        type: DataTypes.DATE,
      
      

      },

amount: {
        type: DataTypes.DECIMAL,
      
      

      },

currency: {
        type: DataTypes.TEXT,
      
      

      },

description: {
        type: DataTypes.TEXT,
      
      

      },

location: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

paid_at: {
        type: DataTypes.DATE,
      
      

      },

points: {
        type: DataTypes.INTEGER,
      
      

      },

severity: {
        type: DataTypes.TEXT,
      
      

      },

reported_by: {
        type: DataTypes.TEXT,
      
      

      },

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

  incidents.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.incidents.belongsTo(db.companies, {
      as: 'company',
      foreignKey: {
        name: 'companyId',
      },
      constraints: false,
    });

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

    db.incidents.belongsTo(db.driver_profiles, {
      as: 'driver_profile',
      foreignKey: {
        name: 'driver_profileId',
      },
      constraints: false,
    });




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

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



  return incidents;
};


