import { LoginPage } from '@admin-lib/index';
import { Provider_Type, User_Type } from '@support-onboard/index';
import { LocationUtility, Utility } from '@utility-lib/index';
import { BlackCarInterceptApis, BlackCar } from '@blackCar-lib/index';
import { ProfileInterceptApis, DelegateInfo } from '@profile-lib/index';
import { HotelInterceptApis, bookHotel } from '@hotel-lib/index';
import { FlightInterceptApis } from '@flight-lib/index';
import { RentalCarInterceptApis } from '@rentalCar-lib/index';
import {
  RentalCarDropOffType,
  RentalCarLocationType,
  RentalCarParams,
  RentalCarUtility
} from '@rentalcar-modal/index';
import { FlightBookingUtility } from '@flight-modal/flight_booking_utility';

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

describe('Personal Travel: Delegate booking by login as - All LOBs', () => {
  beforeEach(() => {
    LoginPage.createNewCompanyAndLoginWithUserByType({
      providers: [Provider_Type.ALL_CAR],
      users: [User_Type.ADMIN]
    });
    cy.enableBlackCarPolicy();
    BlackCarInterceptApis.interceptBlackCarApis();
    ProfileInterceptApis.interceptProfileApis();
    HotelInterceptApis.interceptHotelApis();
    FlightInterceptApis.interceptFlightsApis();
    RentalCarInterceptApis.interceptRentalCarApis();
  });

  it('C5395139: Book hotel by delegate - login as', { tags: ['@tier1'] }, () => {
    const tripTileType = 'Personal';
    LoginPage.createNewTravelerAndLogin();
    DelegateInfo.visitProfileContactInfo();
    DelegateInfo.getDataFromCachedAdminUserAndSetHimAsDelegatedUser();
    Utility.loginAsAdmin(newUserPassword);
    Utility.visitSearchPage();
    BlackCar.loginAsDelegatedUser();
    BlackCar.waitSearchPageIsReloaded();
    BlackCar.waitUserInfoAndVerifyIt();
    bookHotel(tripTileType);
  });

  it.skip('C5395138: Book flight by delegate - login as', { tags: ['@tier1'] }, () => {
    const tripTileType = 'Personal';
    LoginPage.createNewTravelerAndLogin();
    DelegateInfo.visitProfileContactInfo();
    DelegateInfo.getDataFromCachedAdminUserAndSetHimAsDelegatedUser();
    Utility.loginAsAdmin(newUserPassword);
    Utility.visitSearchPage();
    BlackCar.loginAsDelegatedUser();
    BlackCar.waitSearchPageIsReloaded();
    BlackCar.waitUserInfoAndVerifyIt();
    FlightBookingUtility.bookOneWayFlight(tripTileType);
  });

  it('C5395140: Book rental car by delegate - login as', { tags: ['@tier2'] }, () => {
    const locations = LocationUtility.getCitiesUSAsPickUpAndDropOff();
    const outOfPolicy = 'No';
    LoginPage.createNewTravelerAndLogin();
    DelegateInfo.visitProfileContactInfo();
    DelegateInfo.getDataFromCachedAdminUserAndSetHimAsDelegatedUser();
    Utility.loginAsAdmin(newUserPassword);
    Utility.visitSearchPage();
    BlackCar.loginAsDelegatedUser();
    BlackCar.waitSearchPageIsReloaded();
    BlackCar.waitUserInfoAndVerifyIt();
    const rentalCarParams: RentalCarParams = {
      tripTileType: 'Personal',
      dropOffType: RentalCarDropOffType.differentDropOff,
      pickUpLocation: locations[0],
      outOfPolicy: outOfPolicy,
      dropOffLocation: locations[1],
      rentalCarLocationType: RentalCarLocationType.airport
    };
    RentalCarUtility.bookRentalCar(rentalCarParams);
  });
});
