
    +`j                         d dl Z d dlZd dlmZ d dlmZ d dlZ ej                  e      Z	h dZ
h dZdhZd Zd Zd	ed
efdZdedededefdZy)    N)deepcopy)settings>   tax_idtype_id	policy_id	reserv_id
auto_added
customerId
product_id
res_tax_idcustomer_idtravellerIdroom_stay_idsub_hotel_idcollect_whichsiteminder_idcreated_by_usercurrent_billingselectedRatePlanIdsource_of_creationcustomer_traveller_idproducts_added_while_createroom_number_locked_indicator>   cvccvvpinssncardtokenexpirysecretpassword	cc_number
auth_token
expirationcard_numbercredit_cardaccess_tokenpayment_tokenrefresh_tokenreservation_datac                     t        | t              syt        j                  dd|       }dt	        |      cxk  rdk  ry yy)NFz\D       T)
isinstancestrresublen)valuedigitss     A/var/www/html/ls-ibe-bot-apis/app/agents/tools/get_reservation.py_looks_sensitiver8   =   sA    eS! VVE2u%F	S[B      c                    t        | t              rji }| j                         D ]S  \  }}|t        v r|t        v r|j                         t        v r/t        |      r;t        |      }|d dg i fv rO|||<   U |S t        | t              r[g }t               }| D ]H  }t        |      }|d di g fv rt        |      }||v r'|j                  |       |j                  |       J |S | S )Nr-   )r0   dictitemsREMOVE_DUPLICATE_SECTIONSREMOVE_KEYSlowerSENSITIVE_KEYSr8   _cleanlistsetrepraddappend)	objcleanedkvr5   resultseenitemmarkers	            r7   rA   rA   I   s	   #tIIKDAq --KwwyN*"1IE 	  GAJ5  8 	C	uD$<Db"b)) $ZF~HHVMM$  Jr9   payloadreturnc                     t        |       } t        |       }d|v rd|v r|j                  dd       |j                  d      }t	        |t
              r$|j                  dd       |j                  dd       |S )z
    Clean reservation payload before sending to an LLM.

    - removes internal IDs
    - removes sensitive data
    - removes empty values
    - removes duplicate sections
    - preserves guest-facing reservation information
    reservationr+   NoveralltotalsresortFeePos)r   rA   popgetr0   r;   )rO   rH   rR   s      r7   clean_reservation_payloadrW      su     wGWoG 	 ')&- ++m,K+t$. 	-Nr9   confirmation_numberemailhotel_idr   c           	        K   	 t        j                  d      4 d {   }|j                  t        j                  dz   d| |ddi||d       d {   }|j                         j                  d	d
      dk(  rddicd d d       d {    S |j                  t        j                  dz   | dd||d       d {   }|j                         }|j                  d	d
      dk(  r+t        |j                  d            cd d d       d {    S ddicd d d       d {    S 7 7 7 7 p7 #7 # 1 d {  7  sw Y   y xY w# t        $ r&}t        j                  d|        ddicY d }~S d }~ww xY ww)Ng      N@)timeoutz)frontend/Reservations/checkValidConfEmaildata   )confirmationrY   rZ   )rZ   r   )jsonheadersstatusr-   errorzLReservation not found. Confirmation number (Itenrary) or email is incorrect.z#frontend/Reservations/loadOrderInfoF)r_   get_payment_datasuccesszError getting reservation: z2Error getting reservation. Please try again later.)httpxAsyncClientpostr   
LS_API_URLr`   rV   rW   	Exceptionloggerrc   )	rX   rY   rZ   r   clientcheckresponser]   es	            r7   get_reservationrp      s    $O$$T22f ++##&QQ(;!&$% !)$0 &  E zz|"-8!op! 322$ $[[##&KK$7(-
 !)$0 ) 	 	H ==?Dxx"%20&1AB= 322@  !opA 322 3$	% 32222B  O21#67MNNOs   E=E D)E 2D6D,*D6?E D.E E=.D6?D0 AD6E D2E E=D6E #D4$E (E=)E ,D6.E 0D62E 4E 6E<D?=EE E=E 	E:E5/E:0E=5E::E=)r2   rf   copyr   app.configs.settingsr   logging	getLogger__name__rk   r>   r@   r=   r8   rA   r;   rW   r1   rp    r9   r7   <module>rw      s    	   ) 			8	$2,  
	7tt  >%Os %O3 %O# %O]` %Or9   