import { GuestInvite } from '@admin-factory/interface';

import { faker } from '@faker-js/faker';
import { Dates, LocationUtility } from '@utility-lib/index';

export function createHotelGuestInvite(): GuestInvite {
  const airportUSWithLocationId = LocationUtility.getAirportUSWithLocationId();
  const hotelGuestInvite = {
    invitees: [
      {
        givenName: faker.name.firstName(),
        familyName: faker.name.lastName().replace(/'/g, ''),
        email: '',
        billTo: 'Not Applicable',
        department: 'Not Applicable'
      }
    ],
    tripInvitation: {
      extraGuestAllowed: false,
      purpose: `HotelEvent-${faker.datatype.number({ min: 10000000 })}`,
      location: airportUSWithLocationId.location,
      customBookingWindowDays: null,
      hasCustomBookingWindow: false,
      hotelRestrictions: false,
      returnFlightTimeLocked: false,
      destinationAirport: '',
      flightBookingAllowed: false,
      flightBookingInstructions: '',
      flightMaxPriceLocale: '',
      recommendedHotels: [],
      hotelBookingAllowed: true,
      hotelBookingInstructions: '',
      hotelMaxPriceLocale: '',
      railBookingAllowed: false,
      railBookingInstructions: '',
      railMaxPriceLocale: '',
      carRentalCompanyName: '',
      carBookingAllowed: false,
      carBookingInstructions: '',
      carMaxPriceLocale: '',
      flightItineraryType: [],
      railItineraryType: [],
      generalInstructions: '',
      companyPaymentMethodUuid: '',
      hotelRateTypes: ['PAY_NOW'],
      startDateTime: Dates.getDateTime(2).slice(0, 10).concat('T12:00'),
      endDateTime: Dates.getDateTime(4).slice(0, 10).concat('T12:00'),
      travelEarliestDepartureDateTime: Dates.getDateTime(1).slice(0, 10).concat('T12:00'),
      travelLatestReturningDateTime: Dates.getDateTime(5).slice(0, 10).concat('T12:00'),
      contact: {
        uuid: ''
      },
      flightMaxPrice: 0,
      railMaxPrice: 0,
      hotelMaxPrice: 0,
      carMaxPrice: 0,
      locationGooglePlaceId: airportUSWithLocationId.locationGoogleId,
      billTo: '',
      department: '',
      reminderEmailConfig: {
        repeatEveryDays: null,
        remindBeforeDays: null
      },
      companyPolicyLevel: {
        level: 'DEFAULT',
        mediumHaulEnabled: true,
        name: 'DEFAULT',
        uuid: ''
      },
      companyCarDirectBillPaymentMethods: [],
      customFieldValues: []
    }
  };

  cy.task('getDataFromCache', 'userResponse').then((response: any) => {
    hotelGuestInvite.tripInvitation.contact.uuid = response.uuid;
    hotelGuestInvite.tripInvitation.companyPolicyLevel.uuid =
      response.companyPolicyLevel.uuid;
    hotelGuestInvite.invitees[0].email = response.email;
  });

  cy.task('getDataFromCache', 'paymentMethod').then((paymentMethodResponse: any) => {
    hotelGuestInvite.tripInvitation.companyPaymentMethodUuid = paymentMethodResponse.uuid;
  });

  return hotelGuestInvite;
}
