import { LoginPage } from '@admin-lib/index';
import { LocationUtility, Utility, Random } from '@utility-lib/index';
import { HotelInterceptApis, Hotels, HotelCheckout } from '@hotel-lib/index';
import { FlightInterceptApis, FlightTripType } from '@flight-lib/index';
import { FlightBookingUtility } from '@flight-modal/index';
import {
  RentalCarInterceptApis,
  RentalCar,
  RentalCarSearchResults,
  RentalCarCheckout
} from '@rentalCar-lib/index';
import { PersonalHomeScreen } from '../../../lib/personal_homescreen';

const newUserCredentials = Cypress.env('newUser').NEW_USER_PASSWORD;

describe('Personal Travel: Delegate booking by changing traveler - All LOBs', () => {
  beforeEach(() => {
    LoginPage.loginAsCompanyDelegate(newUserCredentials);
    Utility.visitSearchPage();
    Utility.selectTripTileType('Personal');
    HotelInterceptApis.interceptHotelApis();
    FlightInterceptApis.interceptFlightsApis();
    RentalCarInterceptApis.interceptRentalCarApis();
  });

  it('C5389625: Book hotel by delegate - change traveler', { tags: ['@tier2'] }, () => {
    const tab = 'hotel';
    Utility.selectVertical(tab);
    Hotels.selectOneTraveller('personal');
    PersonalHomeScreen.bookPersonalHotel();
  });

  it('C5389071: Book flight by delegate - change traveler', { tags: ['@tier2'] }, () => {
    const flightBookingParams = FlightBookingUtility.initFlightBookingParams({
      locations: LocationUtility.getPairOfOriginAndDestinationAirportsUS(),
      flightTripType: FlightTripType.ONEWAY,
      tripTileType: 'Personal',
      checkInType: ' Continue without EarlyBird Check-In® '
    });
    Utility.selectVertical(flightBookingParams.verticalType);
    Hotels.selectOneTraveller('personal');
    PersonalHomeScreen.bookPersonalFlight();
  });

  it(
    'C5390182: Book rental car by delegate - change traveler',
    { tags: ['@tier2'] },
    () => {
      const tab = 'car';
      Utility.selectVertical(tab);
      Hotels.selectOneTraveller('personal');
      RentalCar.setPickUpAndDropOffDate();
      RentalCar.selectPickUpLocation(LocationUtility.getAirportUS());
      RentalCar.searchRentalCar();
      RentalCarSearchResults.selectCar();
      RentalCarCheckout.setTripInfo();
      HotelCheckout.updateEmailDetails(
        'personal-' + Random.randomString(12) + '@staging-prime.tripactions.xyz'
      );
      RentalCarCheckout.setAcknowledgement();
      RentalCarCheckout.checkOutCar();
      RentalCarCheckout.expectRentalCarBookingSuccessfully('Car confirmed!');
    }
  );
});
