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

license_country: {
        type: DataTypes.TEXT,
      
      

      },

license_number: {
        type: DataTypes.TEXT,
      
      

      },

license_issued_at: {
        type: DataTypes.DATE,
      
      

      },

license_expires_at: {
        type: DataTypes.DATE,
      
      

      },

license_restrictions: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

cpc_number: {
        type: DataTypes.TEXT,
      
      

      },

cpc_issued_at: {
        type: DataTypes.DATE,
      
      

      },

cpc_expires_at: {
        type: DataTypes.DATE,
      
      

      },

cpc_center: {
        type: DataTypes.TEXT,
      
      

      },

cpc_last_training_at: {
        type: DataTypes.DATE,
      
      

      },

cpc_next_training_at: {
        type: DataTypes.DATE,
      
      

      },

cpc_type: {
        type: DataTypes.TEXT,
      
      

      },

adr_number: {
        type: DataTypes.TEXT,
      
      

      },

adr_expires_at: {
        type: DataTypes.DATE,
      
      

      },

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

      },

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

      },

adr_last_course_at: {
        type: DataTypes.DATE,
      
      

      },

adr_next_course_at: {
        type: DataTypes.DATE,
      
      

      },

adr_restrictions: {
        type: DataTypes.TEXT,
      
      

      },

medical_cert_number: {
        type: DataTypes.TEXT,
      
      

      },

medical_issued_by: {
        type: DataTypes.TEXT,
      
      

      },

medical_expires_at: {
        type: DataTypes.DATE,
      
      

      },

psych_test_number: {
        type: DataTypes.TEXT,
      
      

      },

psych_expires_at: {
        type: DataTypes.DATE,
      
      

      },

eye_exam_at: {
        type: DataTypes.DATE,
      
      

      },

cardio_exam_at: {
        type: DataTypes.DATE,
      
      

      },

medical_restrictions: {
        type: DataTypes.TEXT,
      
      

      },

tacho_card_number: {
        type: DataTypes.TEXT,
      
      

      },

tacho_country: {
        type: DataTypes.TEXT,
      
      

      },

tacho_expires_at: {
        type: DataTypes.DATE,
      
      

      },

tacho_last_download_at: {
        type: DataTypes.DATE,
      
      

      },

tacho_next_download_at: {
        type: DataTypes.DATE,
      
      

      },

violations_count: {
        type: DataTypes.INTEGER,
      
      

      },

warnings_count: {
        type: DataTypes.INTEGER,
      
      

      },

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

      },

driving_ban_until: {
        type: DataTypes.DATE,
      
      

      },

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

  driver_compliances.associate = (db) => {


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
















    db.driver_compliances.hasMany(db.driver_profiles, {
      as: 'driver_profiles_compliance',
      foreignKey: {
          name: 'complianceId',
      },
      constraints: false,
    });
































//end loop



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




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

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



  return driver_compliances;
};


