import { LoginPage } from '@admin-lib/index';
import {
  RentalCarCheckout,
  RentalCarLocationType,
  RentalCarDropOffType,
  RentalCarInterceptApis,
  RentalCarSearchResults
} from '@rentalCar-lib/index';
import { User_Type } from '@support-onboard/data_model/user_type';
import { TripApproval, CreateProposal, TripProposalInterceptApis, TripProposalBooking } from '@tripProposal-lib/index';
import { Timeouts } from '@utility-lib/constants';

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

describe.skip('Cars: Trip proposal', () => {
  beforeEach(() => {
    RentalCarInterceptApis.interceptRentalCarApis();
    TripProposalInterceptApis.tripIntercepts();
    LoginPage.createNewCompanyAndLoginWithUserByType({
      users: [User_Type.ADMIN],
      tripProposal: true
    });
    cy.enableTripProposal();
  });

  it('C619959 C51019: Verify car booking via trip proposal flow', { tags: ['@tier1'] }, () => {
    LoginPage.createNewTravelerAndLogin();
    CreateProposal.visitNewTripProposalPage();
    CreateProposal.setTripName();
    CreateProposal.setTripReason();
    CreateProposal.setBookingType('car');
    TripProposalBooking.carBooking();
    CreateProposal.sendProposal();
    CreateProposal.sendRequestToManager();
    CreateProposal.loginAsAdmin(newUserCredentials);
    CreateProposal.visitAdminPage();
    TripApproval.viewApproval('APPROVALS_PROPOSALS');
    TripApproval.expectTripProposalIsCreated('Berlin Trip');
    TripApproval.approveTripProposal();
    CreateProposal.loginAsTraveler();
    CreateProposal.visitNewTripProposalPage();
    TripProposalBooking.startBooking();
    cy.wait(Timeouts.MEDIUM_TIMEOUT_10_SEC.timeout);
    RentalCarSearchResults.selectCar();
    RentalCarCheckout.waitToBeLoaded();
    RentalCarCheckout.setTripInfo();
    RentalCarCheckout.checkOutCar(false, RentalCarLocationType.airport, RentalCarDropOffType.differentDropOff);
    TripProposalBooking.expectTripProposalBookingSuccessfully();
  });
});
