import {
  RentalCarDropOffType,
  RentalCarLocationType,
  RentalCarParams,
  RentalCarUtility
} from '@rentalcar-modal/index';
import { LoginPage } from '@admin-lib/index';
import { User_Type } from '@support-onboard/index';
import { Emea_Fee_Types } from '@support-commerce/data_model/fee_types';
import { RentalCarInterceptApis, RentalCarItinerary, Trips } from '@rentalCar-lib/index';
import { CarInvoiceValidation } from '@commerce-lib/cars/invoice_validation';
import { stagingUsers } from '@fixtures/staging-users';
import { TripFeeValidation } from '@commerce-lib/tripfee/trip_fee_validation';
import { CommerceApiIntercepts } from '@commerce-shared-lib/index';
import { Timeouts } from '@utility-lib/constants';

const emeaFeesTagSet: Array<string> = [
  'inventoryTypeCar',
  'bookingOnline',
  'tripOnline',
  'booking1'
];
const adminCredentials = Cypress.env('superAdmin').SUPER_ADMIN_PASSWORD;
const emeaFeeModelType = Emea_Fee_Types.EMEA_FEE_MODEL_A_USD_N;

describe('Commerce: RENTAL CAR| USD | Booking  and Cancel Test', () => {
  beforeEach(() => {
    CommerceApiIntercepts.interceptCommerceApis();
    cy.loginWithAuthToken({
      email: stagingUsers.superAdmin.email,
      password: adminCredentials,
      isSA: true
    });
    TripFeeValidation.getAndStoreFeeModelUUID(emeaFeeModelType);
    TripFeeValidation.getTripFeeUsingFeeModelUUID(emeaFeesTagSet);
    LoginPage.createNewCompanyAndLoginWithUserByType({
      users: [User_Type.TRAVELER],
      feeModelInfo: Emea_Fee_Types.EMEA_FEE_MODEL_A_USD_N
    });
    RentalCarInterceptApis.interceptRentalCarApis();
  });

  it(
    'C1204948: Validate EMEA Trip Fee for rental car booking',
    { tags: ['@tier1'] },
    () => {
      const outOfPolicy = 'No';
      const rentalCarParams: RentalCarParams = {
        tripTileType: 'Business',
        dropOffType: RentalCarDropOffType.differentDropOff,
        pickUpLocation: 'DEN - Denver Intl Airport',
        outOfPolicy: outOfPolicy,
        dropOffLocation: 'DFW - Dallas/Fort Worth Intl Airport',
        rentalCarLocationType: RentalCarLocationType.airport
      };
      RentalCarUtility.bookRentalCar(rentalCarParams);
      Trips.validateTripDetails();
      RentalCarItinerary.waitToBeLoaded();
      CarInvoiceValidation.storeCarBookingID();
      cy.wait(Timeouts.MEDIUM_TIMEOUT_20_SEC.timeout);
      RentalCarItinerary.verifyTripFeeInInvoice();
    }
  );
});
