import { guidRegex } from '@utility-lib/index';
import { SharedIntercepts } from '@intercepts-lib/index';

const rentalCarBaseUrl = '/api/v1/trip/car';

export class RentalCarInterceptApis {
  static interceptRentalCarApis() {
    SharedIntercepts.intercepts();

    //### SEARCH HOME PAGE
    cy.intercept('GET', new RegExp(`${rentalCarBaseUrl}/searches/`)).as(
      'waitForCarSearchResults'
    );

    //### SEARCH RESULTS PAGE
    cy.intercept(
      'POST',
      new RegExp(`${rentalCarBaseUrl}/searches/${guidRegex}/cars/${guidRegex}/contract`)
    ).as('waitForSelectCar');
    cy.intercept(
      'GET',
      new RegExp(`${rentalCarBaseUrl}/searches/${guidRegex}/contracts/${guidRegex}`)
    ).as('waitForCarContract');
    cy.intercept(
      'GET',
      new RegExp(`${rentalCarBaseUrl}/searches/${guidRegex}/matchingTrips\\?.+`)
    ).as('waitForMatchingTrips');

    //### CHECKOUT PAGE
    cy.intercept(
      'POST',
      new RegExp(`${rentalCarBaseUrl}/searches/${guidRegex}/contracts/${guidRegex}/book`)
    ).as('waitForRentalCarCheckout');
    cy.intercept('POST', '**/book?hold=false**').as('waitForBooking');

    //### TRIPS PAGE
    cy.intercept('GET', /\/api\/user\/bookableUsers\/guests/).as('waitForTripsPageLoad');

    cy.intercept('GET', new RegExp('/api/invoices/v2/sync_status/')).as(
      'waitForLoadTripPage'
    );
    cy.intercept('GET', '/api/user/files/policy/policyFile').as('waitForPolicyFile');
  }
}
