import { LoginPage } from '@admin-lib/index';
import { eventData } from '@fixtures/event/event_data';
import {
  CreateEvent,
  EventsWorkflow,
  Invitations,
  TeamEventParams
} from '@group-events-lib/index';
import { Provider_Type, User_Type } from '@support-onboard/index';
import { FlightBookingUtility, FlightUtility } from '@flight-modal/index';
import {
  FlightInterceptApis,
  FlightCheckout,
  Flights,
  FlightTripType
} from '@flight-lib/index';

describe('GME: Team event: flight booking', () => {
  it('C50997: Book a roundtrip flight in group travel', { tags: ['@tier1'] }, () => {
    const flightBookingParams = FlightBookingUtility.initFlightBookingParams({
      locations: ['NYC - All Airports, New York, United States, New York, United States'],
      flightTripType: FlightTripType.ROUNDTRIP,
      isItEventSearch: true
    });
    LoginPage.createNewCompanyAndLoginWithUserByType({
      providers: [Provider_Type.SABRE_FLIGHT],
      users: [User_Type.ADMIN]
    });

    cy.task('getDataFromCache', 'userResponse').then((response: any) => {
      const teamEventParams: TeamEventParams = {
        eventName: eventData.eventName,
        locationType: eventData.locationType,
        invitees: [{ id: response.uuid, email: response.email }],
        startDate: eventData.startDateTime,
        endDate: eventData.endDateTime,
        placeId: eventData.placeId
      };
      EventsWorkflow.createTeamEvent(teamEventParams);
    });

    FlightInterceptApis.interceptFlightsApis();
    CreateEvent.openSearchPage();
    Invitations.verifyInvitationName(eventData.eventName);
    CreateEvent.selectTeamEventVertical('flight');
    // added hot fix as we are currently planning to fix flight sold out issues
    Flights.setOrigin(flightBookingParams.locations[0]);
    Flights.searchFlight(true);
    FlightUtility.runChooseResultFlow(flightBookingParams);
    FlightCheckout.saveTripInformation();
    FlightCheckout.checkCancellationPolicy();
    FlightCheckout.acceptOutOfPolicyFlight();
    FlightCheckout.validateIfPassportAndVisaInfoRequired();
    FlightCheckout.checkIn('Skip');
    FlightCheckout.updateContactDetails();
    FlightCheckout.bookAndPay(flightBookingParams);
  });
});
