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

vehicle_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"walking",


"bicycle",


"motorbike",


"car",


"van"

        ],

      },

government_id_number: {
        type: DataTypes.TEXT,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"pending",


"active",


"suspended"

        ],

      },

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

      },

rating_average: {
        type: DataTypes.DECIMAL,
      
      

      },

rating_count: {
        type: DataTypes.INTEGER,
      
      

      },

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

  courier_profiles.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.courier_profiles.belongsTo(db.users, {
      as: 'user',
      foreignKey: {
        name: 'userId',
      },
      constraints: false,
    });

    db.courier_profiles.belongsTo(db.addresses, {
      as: 'current_address',
      foreignKey: {
        name: 'current_addressId',
      },
      constraints: false,
    });

    db.courier_profiles.belongsTo(db.organizations, {
      as: 'organizations',
      foreignKey: {
        name: 'organizationsId',
      },
      constraints: false,
    });



    db.courier_profiles.hasMany(db.file, {
      as: 'verification_files',
      foreignKey: 'belongsToId',
      constraints: false,
      scope: {
        belongsTo: db.courier_profiles.getTableName(),
        belongsToColumn: 'verification_files',
      },
    });

    db.courier_profiles.hasMany(db.file, {
      as: 'profile_images',
      foreignKey: 'belongsToId',
      constraints: false,
      scope: {
        belongsTo: db.courier_profiles.getTableName(),
        belongsToColumn: 'profile_images',
      },
    });


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

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



  return courier_profiles;
};


