import { LoginPage } from '@admin-lib/index';
import { User_Type } from '@support-onboard/index';
import { LocationUtility, Utility } from '@utility-lib/index';
import { BlackCar, BlackCarItinerary, BlackCarUtility } from '@blackCar-lib/index';
import { ProfileInterceptApis, DelegateInfo } from '@profile-lib/index';

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

describe('Black car: delegate booking', () => {
  beforeEach(() => {
    BlackCarUtility.prepareCompanyAndLogin(User_Type.ADMIN);
    cy.enableBlackCarPolicy();
    ProfileInterceptApis.interceptProfileApis();
  });

  it('C50119: Should be able to book black car as delegated user', { tags: ['@tier1'] }, () => {
    const tripTileType = 'Business';
    LoginPage.createNewTravelerAndLogin();
    DelegateInfo.visitProfileContactInfo();
    DelegateInfo.getDataFromCachedAdminUserAndSetHimAsDelegatedUser();
    Utility.loginAsAdmin(newUserPassword);

    Utility.visitSearchPage();
    BlackCar.loginAsDelegatedUser();
    BlackCar.waitSearchPageIsReloaded();
    BlackCar.waitUserInfoAndVerifyIt();

    BlackCarUtility.blackCarBookingHourly(LocationUtility.getAddressUS(), 2, tripTileType);
    BlackCarItinerary.verifyBookForDelegatedUser();
    BlackCarItinerary.cancelBlackCar();
  });
});
