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

origin: {
        type: DataTypes.TEXT,
      
      

      },

destination: {
        type: DataTypes.TEXT,
      
      

      },

depart_at: {
        type: DataTypes.DATE,
      
      

      },

return_at: {
        type: DataTypes.DATE,
      
      

      },

trip_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"one_way",


"round_trip",


"multi_city"

        ],

      },

cabin: {
        type: DataTypes.ENUM,
      
      

        values: [

"economy",


"premium_economy",


"business",


"first"

        ],

      },

travelers_count: {
        type: DataTypes.INTEGER,
      
      

      },

max_budget: {
        type: DataTypes.DECIMAL,
      
      

      },

preferences: {
        type: DataTypes.TEXT,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"draft",


"searching",


"needs_confirmation",


"booked",


"canceled",


"failed"

        ],

      },

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

  travel_requests.associate = (db) => {


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


























    db.travel_requests.hasMany(db.travel_bookings, {
      as: 'travel_bookings_travel_request',
      foreignKey: {
          name: 'travel_requestId',
      },
      constraints: false,
    });






//end loop



    db.travel_requests.belongsTo(db.users, {
      as: 'user',
      foreignKey: {
        name: 'userId',
      },
      constraints: false,
    });

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




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

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



  return travel_requests;
};


