text: const {getHotelReservation, getAirlineReservation,getAutoReservation, seedUsers, seedAirlineItems,seedHotelItems,seedAutoItems} = require('./helpers/seederHelper')
  const {getReservation, getReservations} = require('../../agent/datastore');
  const faker = require('faker');
  const random = (max) => {
      return Math.floor(Math.random() * max)
  };
  const incrementDate = (startDate, daysToAdd) => {
      const newdate = new Date();
      newdate.setDate(startDate.getDate() + daysToAdd);
      return newdate;
  };
  
  const sample = (items) => {
      return items[Math.floor(Math.random() * items.length)];
  };
  
  const seed = async (numOfRes) => {
  
      const reservations = await getReservations();
      if (reservations.length > 0) return reservations;
  
      //Seed the inventory items
      await seedAirlineItems()
      await seedHotelItems()
      await seedAutoItems()
      await seedUsers()
  
      const users = await require('../../users/datastore').getUsers();
  
      const cnt = numOfRes || 10;
      const user = sample(users);
  
      const startDate = new Date();
      const daysToAdd = random(7);
      const endDate = incrementDate(startDate, daysToAdd);
  
      //make an auto reservation and hold it
      const config = {};
      config.user = user;
      config.startDate = startDate;
      config.endDate = endDate;
      config.vendor = 'Seeder';
      const results = [];
      for (let i = 0; i < cnt; i++) {
          //make an auto reservation and hold it
          const autoRes = await getAutoReservation(config);
  
          //make an airline reservation and hold it
          const airlineRes = await getAirlineReservation(config);
  
          //make an hotel reservation and hold it
          const hotelRes = await getHotelReservation(config);
  
          const reservation = await getReservation();
          reservation.user = user
          reservation.airline = airlineRes
          reservation.auto = autoRes
          reservation.hotel = hotelRes
          const result = await reservation.save();
          results.push(result);
      }
  
      return results;
  }
  
  
  
  seed()
      .then(result => {
          console. log({message: "Done with seeding"})
          process.exit();
      })
      .catch(e => {
          console. log({message: e.message})
      })
  
  module.exports = {seed};