import { FlightBookingUtility } from '@flight-modal/index';
import { FlightTripType } from '@flight-lib/search';
import { LocationUtility } from '@utility-lib/location';
import { Directions, FlightBookingData } from '@chat-lib/booking';
import { HelpCenter } from '@helpcenter-lib/helpcenter';
import { ChatApiIntercept, ChatBooking, ChatBox, CSat, Banner } from '@chat-lib/index';
import { LoginPage } from '@admin-lib/index';
import { FlightInterceptApis } from '@flight-lib/index';
import { Timeouts } from '@utility-lib/index';
import { Provider_Type, User_Type } from '@support-onboard/index';

describe('Chat: ML unsupported flows', () => {
  xit(
    'C9615707: Use chat to change flight booking via ML unsupported flow',
    { tags: ['@tier2'] },
    () => {
      const flightBookingParams = FlightBookingUtility.initFlightBookingParams({
        locations: LocationUtility.getPairOfOriginAndDestinationAirportsUSWithShortName(),
        flightTripType: FlightTripType.ROUNDTRIP,
        tripTileType: 'Business'
      });
      const flightBookingData: FlightBookingData = {
        flightBookingParams: flightBookingParams,
        departingFrom: Directions.FROM,
        arrivingAt: Directions.TO,
        isChangeFlight: true
      };
      const daysToMove = { daysToMove: 8, daysAfterMovedDays: 2 };

      ChatApiIntercept.interceptChatApis();
      FlightInterceptApis.interceptFlightsApis();
      LoginPage.createNewCompanyAndLoginWithUserByType({
        users: [User_Type.ADMIN],
        providers: [Provider_Type.SABRE_FLIGHT],
        companySuffix: '-avamltest'
      });
      HelpCenter.visitPage();
      ChatBox.openChatWithAva();
      ChatBox.typeMsgToAva(`I want to book a flight to ${flightBookingParams.locations}`);
      ChatBox.expectMsgReceivedFromAva(`provide`);
      ChatBooking.enterShiftedDates(daysToMove);
      ChatBox.readAvaMsgAndTypeReply('confirm', 'Yes');
      ChatBooking.continueBookTripFlight(flightBookingData);
      ChatBooking.checkIsChatMinimized();

      ChatBox.openChat();
      ChatBox.closeChat();
      ChatBox.confirmCloseChat();
      ChatBox.startNewChatWithAva();
      ChatBox.typeMsgToAva(
        `I want to change the meal on my upcoming flight to vegetarian`
      );
      ChatBox.readAvaMsgAndTypeReply('confirm', 'Yes');
      ChatBox.readAvaMsgAndSelectReply('part of the trip', 'Both flights');
      ChatBox.waitUntilAvaStopTyping();
      cy.wait(Timeouts.MEDIUM_TIMEOUT_30_SEC.timeout);
      CSat.submitCSatScore(5);
      CSat.expectCSatScoreSubmitted(5);
      CSat.skipAndConnetWithAgent();
      Banner.expectBannerContainsText('An agent will be with you shortly.');
    }
  );
});
