a
    ii                     @   s^   d Z ddlmZmZmZ ddlZddlmZ ddeeeeeef  eeef dddZ	dS )	zhihaho API bridge (MVP stub + optional server-side proxy).

Assumption A1: actual branch/jump APIs depend on hihaho product documentation.
Use HIHaho Client only when HIHAHO_API_BASE and HIHAHO_API_KEY are set.
    )AnyDictOptionalN)settings)metadata)film_session_id
branch_keyr   returnc           
   	      s>  t jpdd}|rt js0ddd| ||p*i dS t jp8d}|dsLd| }| | }dd	t j i}| |d
|pvi }tjdd4 I dH }|j|||dI dH }	|		  z&d||	
 dW W  d  I dH  S  ty
   d||	jd Y W  d  I dH  S 0 W d  I dH  q:1 I dH s00    Y  dS )zVPOST to hihaho proxy endpoint if configured; otherwise return a safe fallback payload. /FTZhihaho_api_not_configured)okZskippedreasonr   r   r   z/interactive/resolutionZAuthorizationzBearer )ZfilmSessionIdZ	branchKeyg      .@)timeoutN)jsonheaders)r   Zendpointdata)r   Zhihaho_api_baserstripZhihaho_api_keyZhihaho_branch_path
startswithhttpxZAsyncClientZpostZraise_for_statusr   	Exceptiontext)
r   r   r   baseZbranch_pathurlr   ZpayloadZclientZresponse r   app\services\hihaho_client.pynotify_branch_result   s,    
	

&r   )
__doc__typingr   r   r   r   Z
app.configr   strr   r   r   r   r   <module>   s   
