import { LoginPage } from '@admin-lib/index';
import {
  Hotels,
  HotelCheckout,
  HotelSearchResults,
  HotelItinerary,
  HotelInterceptApis,
  bookHotel
} from '@hotel-lib/index';
import { User_Type } from '@support-onboard/index';
import {
  FlightInterceptApis,
  Flights,
  FlightTripType,
  FlightItinerary
} from '@flight-lib/index';
import { FlightUtility, FlightBookingUtility } from '@flight-modal/index';
import {
  RentalCar,
  RentalCarSearchResults,
  RentalCarCheckout,
  RentalCarInterceptApis
} from '@rentalCar-lib/index';
import { LocationUtility, Utility } from '@utility-lib/index';

const flightBookingParams = FlightBookingUtility.initFlightBookingParams({
  locations: LocationUtility.getPairOfOriginAndDestinationAirportsUS(),
  flightTripType: FlightTripType.ROUNDTRIP,
  tripTileType: 'Personal',
  checkInType: ' Continue without EarlyBird Check-In® '
});
describe('Personal Travel: Add to trip - All LOBs', () => {
  beforeEach(() => {
    LoginPage.createNewCompanyAndLoginWithUserByType({ users: [User_Type.TRAVELER] });
    HotelInterceptApis.interceptHotelApis();
    FlightInterceptApis.interceptFlightsApis();
    RentalCarInterceptApis.interceptRentalCarApis();
  });

  it(
    'C5390181: Traveler adds rental car booking to existing trip',
    { tags: ['@tier2'] },
    () => {
      bookHotel('Personal');
      HotelItinerary.visitItinerary();
      HotelItinerary.viewAndManageItinerary();
      HotelItinerary.addNewTripInCurrentItinerary('Rental car');
      RentalCar.searchRentalCar();
      RentalCarSearchResults.selectCar();
      RentalCarCheckout.setTripInfo();
      RentalCarCheckout.setAcknowledgement();
      RentalCarCheckout.checkOutCar();
      RentalCarCheckout.expectRentalCarBookingSuccessfully('Car confirmed!');
      HotelItinerary.visitItinerary();
    }
  );

  it(
    'C5389626: Traveler adds hotel booking to existing trip',
    { tags: ['@tier2'] },
    () => {
      bookHotel('Personal');
      HotelItinerary.visitItinerary();
      HotelItinerary.viewAndManageItinerary();
      HotelItinerary.addNewTripInCurrentItinerary('Hotel');
      Hotels.searchHotel();
      HotelSearchResults.selectHotel(0);
      HotelSearchResults.selectRoomOption();
      HotelCheckout.checkoutFLow('Personal');
      HotelCheckout.expectHotelBookedSuccessfully('Hotel confirmed!');
      HotelItinerary.visitItinerary();
    }
  );

  it(
    'C5395137: Traveler adds flight booking to existing trip',
    { tags: ['@tier2'] },
    () => {
      bookHotel('Personal');
      HotelItinerary.visitItinerary();
      HotelItinerary.viewAndManageItinerary();
      HotelItinerary.addNewTripInCurrentItinerary('Flight');
      Flights.setLocations(['MUC', 'TLV']);
      Utility.selectFutureDate();
      Flights.searchFlight();
      FlightUtility.runChooseResultFlow(flightBookingParams);
      FlightUtility.runCheckoutFlow(flightBookingParams);
      FlightItinerary.viewItineraryPage();
    }
  );
});
