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

full_name: {
        type: DataTypes.TEXT,
      
      

      },

email: {
        type: DataTypes.TEXT,
      
      

      },

phone: {
        type: DataTypes.TEXT,
      
      

      },

nationality: {
        type: DataTypes.TEXT,
      
      

      },

passport_number: {
        type: DataTypes.TEXT,
      
      

      },

date_of_birth: {
        type: DataTypes.DATE,
      
      

      },

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

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

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

  booking_request_travelers.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.booking_request_travelers.belongsTo(db.booking_requests, {
      as: 'booking_request',
      foreignKey: {
        name: 'booking_requestId',
      },
      constraints: false,
    });

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




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

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



  return booking_request_travelers;
};


