import {
  HotelInterceptApis,
  HotelCheckout,
  Hotels,
  HotelSearchResults
} from '@hotel-lib/index';
import { factory } from '@admin-factory/index';
import { LoginPage } from '@admin-lib/index';
import { User_Type, Provider_Type } from '@support-onboard/index';
import { Utility, Timeouts } from '@utility-lib/index';
import { SplitUtility } from '@split-lib/index';

describe('GME: Guest invite booking', () => {
  it('C51010: FE - Hotel booking the Guest invite', { tags: ['@tier1'] }, () => {
    LoginPage.createNewCompanyAndLoginWithUserByType({
      providers: [Provider_Type.EXPEDIA_HOTEL],
      users: [User_Type.ADMIN]
    });

    cy.updateSplits();
    SplitUtility.isSplitOn('GROUP_TRAVEL_REFACTOR').then((refactored) => {
      if (refactored) {
        cy.createGuestTravel(factory.createHotelGuestTravel());
      } else {
        cy.createGuestInvite(factory.createHotelGuestInvite());
      }
    });

    HotelInterceptApis.interceptHotelApis();
    Utility.visitSearchPage();

    Hotels.searchHotelGuest();
    HotelSearchResults.selectHotel();
    HotelSearchResults.selectRoomOption();
    HotelCheckout.setTripInfo();
    HotelCheckout.hotelCancellationAndChargePolicy();
    HotelCheckout.acceptHotelBookingPolicy();
    HotelCheckout.setPhoneNumber();
    HotelCheckout.checkIfProofOfVaccineRequired();
    cy.wait(Timeouts.SHORT_TIMEOUT_5_SEC.timeout);
    HotelCheckout.setTripInfo();
    HotelCheckout.acceptAcknowledgement();
    HotelCheckout.bookNow();
    HotelCheckout.expectHotelBookedSuccessfully('Hotel confirmed!');
  });
});
