
    6VhJ                        d dl mZmZmZmZ d dlmZ d dlmZm	Z	 d dl
mZ d dlmZmZmZmZ d dlmZmZmZmZmZmZ d dlmZ d dlmZ  ed	d
g          Ze                    de           ee           ee          fdededefd            Ze                    dee                    ee           ee          fdededefd            Ze                     dee                    ed d            eddd           ed           ed           ee           ee          fde!de!de	e!         de	e"         dedefd            Z#e                     de           ee           ee          fd e!dedefd!            Z$e                    d"e           ee           ee          fd#ededefd$            Z%e                     d"ee                    ed d            eddd           ed           ee           ee          fde!de!de	e"         dedef
d%            Z&e                    d&           ee          fd'edefd(            Z'dS ))    )	APIRouterDependsHTTPExceptionQuery)Session)ListOptional)get_db)CommunicationCommunicationTemplateUser	Candidate)CommunicationCreateCommunicationBulkCreateCommunicationResponseCommunicationTemplateCreateCommunicationTemplateResponseAIMessageCompositionRequest)get_current_active_user)	AIServicez/communicationsCommunications)prefixtags/)response_modelcommunicationdbcurrent_userc                   K   |                     t                                        t          j        | j        k                                              }|st          dd          t          | j        |j        | j        | j	        | j
                  }|                    |           |                                 |                    |           |S )z#Send a communication to a candidate  zCandidate not foundstatus_codedetailcandidate_iduser_idsubjectbodytype)queryr   filteridr%   firstr   r   r'   r(   r)   addcommitrefresh)r   r   r   	candidatedb_communications        4/home/runner/workspace/app/routers/communications.pysend_communicationr4      s       ##**9<=;U+UVV\\^^I K4IJJJJ$"/%   FFIIKKKJJ       z/bulkc                   K   g }| j         D ]}|                    t                                        t          j        |k                                              }|rRt          ||j        | j        | j        | j	                  }|
                    |           |                    |           |                                 |D ]}|                    |           |S )z*Send communications to multiple candidatesr$   )candidate_idsr*   r   r+   r,   r-   r   r'   r(   r)   r.   appendr/   r0   )r   r   r   communicationsr%   r1   r2   comms           r3   send_bulk_communicationr;   )   s       N%3 4 4HHY''..y||/KLLRRTT	 		4,)$%-"'"'      FF#$$$!!"2333IIKKK  


4r5   )ged      i  )r<   leNskiplimitr%   r)   c                 F  K   |                     t                    }|r#|                    t          j        |k              }|r#|                    t          j        |k              }|                    |                               |                                          }|S )z"List communications with filtering)r*   r   r+   r%   r)   offsetrA   all)r@   rA   r%   r)   r   r   r*   r9   s           r3   list_communicationsrE   G   s       HH]##E I]7<GHH 9]/4788\\$''--e4488::Nr5   z/{communication_id}communication_idc                    K   |                     t                                        t          j        | k                                              }|st          dd          |S )zGet a specific communicationr    zCommunication not foundr!   )r*   r   r+   r,   r-   r   )rF   r   r   r   s       r3   get_communicationrH   \   s_       HH]++22=3CGW3WXX^^``M O4MNNNNr5   z
/templatestemplatec                    K   t          | j        | j        | j        | j        |j                  }|                    |           |                                 |                    |           |S )zCreate a communication template)namer'   r(   r)   
created_by)	r   rK   r'   r(   r)   r,   r.   r/   r0   )rI   r   r   db_templates       r3   create_templaterN   i   so       (] ]]?  K FF;IIKKKJJ{r5   c                 >  K   |                     t                                        t          j        dk              }|r#|                    t          j        |k              }|                    |                               |                                          }|S )zList communication templatesT)r*   r   r+   	is_activer)   rC   rA   rD   )r@   rA   r)   r   r   r*   	templatess          r3   list_templatesrR   }   s       HH*++223H3RVZ3Z[[E A274?@@T""((//3355Ir5   z/ai-composerequestc                 B   K   t          j        |            d{V }d|iS )z!Generate message content using AINgenerated_message)r   compose_message)rS   r   messages      r3   compose_message_with_airX      s5       -g66666666G))r5   )(fastapir   r   r   r   sqlalchemy.ormr   typingr   r	   app.core.databaser
   
app.modelsr   r   r   r   app.schemas.communicationr   r   r   r   r   r   app.services.authr   app.services.ai_servicesr   routerpostr4   r;   getintstrrE   rH   rN   rR   rX    r5   r3   <module>rg      s   < < < < < < < < < < < < " " " " " " ! ! ! ! ! ! ! ! $ $ $ $ $ $ L L L L L L L L L L L L               
 6 5 5 5 5 5 . . . . . .	+3C2D	E	E	ES!677 '&// !899 &    870 WT*?%@AA '&// !899 *    BA: C%: ;<<aAsqT***"'%++%++'&// !899 
 3- 3-	
 	    =<( !2GHH '&// !899	 			 	 	 	 IH	 \*GHH '&// !899 )    IH& L.K)LMMaAsqT***%++'&// !899 
 3- 		
    NM" ] !!899* *(** * * * * *r5   