import { HotelInterceptApis, guestHotelBooking, Hotels } from '@hotel-lib/index';
import { factory } from '@admin-factory/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 { stagingUsers } from '@fixtures/staging-users';
import { TripFeeValidation } from '@commerce-lib/tripfee/trip_fee_validation';
import { HotelInvoiceValidation } from '@commerce-lib/hotels/invoice_validation';
import { Invoice } from '@commerce-lib/invoice/invoice';
import { CommerceApiIntercepts } from '@commerce-shared-lib/api-intercepts';

const userCredentials = Cypress.env('newUser').NEW_USER_PASSWORD;
const adminCredentials = Cypress.env('superAdmin').SUPER_ADMIN_PASSWORD;
const emeaFeeModelType = Emea_Fee_Types.EMEA_FEE_MODEL_A_USD_N;

const emeaFeesTagSet: Array<string> = [
  'bookingOnline',
  'tripOnline',
  'booking1',
  'inventoryTypeHotel'
];

describe('Commerce: HOTEL | BUSINESS | EURO | Guest Invited User Bookings', () => {
  beforeEach(() => {
    let hotel_invitee_email;
    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
    });

    cy.task('getDataFromCache', 'userEmail').then((email: any) => {
      hotel_invitee_email = email;
      cy.createGuestInvite(factory.createHotelGuestInvite());
      LoginPage.clearExistingLoginSession();
      cy.loginWithAuthToken({
        email: hotel_invitee_email,
        password: userCredentials,
        isSA: true
      });
    });
    HotelInterceptApis.interceptHotelApis();
  });

  it(
    'C1204278: Hotel Guest Invite | Verify Hotel Invoice for PREPAY Hotel (EURO)',
    { tags: ['@tier1'] },
    () => {
      guestHotelBooking();
      Hotels.guestItineraryPage();
      HotelInvoiceValidation.storeTripData();
      HotelInvoiceValidation.clickAndDownloadInvoice();
      Invoice.retrieveDownloadInvoiceFile();
      Invoice.retrieveAndConvertPDFInvoiceDetailsToHTML();
      HotelInvoiceValidation.checkInvoiceBookingId();
      HotelInvoiceValidation.checkInvoiceHotelName();
      HotelInvoiceValidation.checkInvoiceTotalPrice();
    }
  );
});
