
    :/fiy
                     x    d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	  e       Z
 G d dej                        Zy)	    )serializers)get_user_model)CallCatchPhrase)Call)ProfileServicesc                      e Zd Z ej                  d      Z ej                         Z ej                  d      Z ej                         Z	 ej                  d      Z ej                  d      Z ej                  d      Z ej                         Z ej                         Z ej                         Z ej                         Zd Zd Zd	 Zd
 Zd Zd Z G d d      Zy)CallPhraseReportSerializerpk)sourcetwilio_call_sid
created_atcaller_namefrom_numberc                      y)N  )selfobjs     L/var/www/html/dp2/backend_v2.1/server/apps/calls/serializers/catch_phrase.pyget_transcriptz)CallPhraseReportSerializer.get_transcript   s        c                     t        |d      s4t        j                  j                  |      j	                  d      |_        |j
                  S )N_prefetched_catch_phrases)callphrase)hasattrr   objectsfilterselect_relatedr   )r   r   s     r   _get_call_phrasesz,CallPhraseReportSerializer._get_call_phrases   sB    t89''T") *
 ---r   c                 r    | j                  |      D cg c]  }|j                  j                   c}S c c}w )N)r    r   r   r   cps      r   get_catch_phrases_foundz2CallPhraseReportSerializer.get_catch_phrases_found%   s>     ,,T2
2 II2
 	
 
s   4c           
          | j                  |      D cg c]Q  }|j                  |j                  j                  |j                  |j                  |j
                  |j                  dS c}S c c}w )N)	phrase_idr   speaker
confidencer   matched_text)r    r&   r   r'   r(   r   r)   r"   s      r   get_catch_phrases_found_detailz9CallPhraseReportSerializer.get_catch_phrases_found_detail+   sj     ,,T2

 3  \\))**:: mm)) " 3

 
	
 

s   AA-c                     |j                   }|s| j                         S |j                  t        j                  ||j
                        |j                  dS )Nidnamephone)transfer_userreturn_emptyr-   r   display_name_for_companycompanytransfer_number)r   r   advisors      r   get_advisorz&CallPhraseReportSerializer.get_advisor8   sO    $$$$&& **#<<WdllS))
 	
r   c                     d dd dS )NzNot Transferredr,   r   )r   s    r   r1   z'CallPhraseReportSerializer.return_emptyC   s    $5EEr   c                       e Zd ZeZg dZy)CallPhraseReportSerializer.Meta)r-   call_idtwilio_call_idsummarycall_date_timecustomer_namecustomer_phone
transcriptcatch_phrases_foundcatch_phrases_found_detailr5   N)__name__
__module____qualname__r   modelfieldsr   r   r   Metar9   F   s    
r   rH   N)rC   rD   rE   r   IntegerFieldr-   	CharFieldr:   r;   r<   DateTimeFieldr=   r>   r?   SerializerMethodFieldr@   rA   rB   r5   r   r    r$   r*   r6   r1   rH   r   r   r   r	   r	   
   s    	!	!	!	.B#k##%G*[**2CDN#k##%G.[..lCN)K))?M*[**-@N2224J;+;;=!B!B!B!D/k//1G.

	
F
 
r   r	   N)rest_frameworkr   django.contrib.authr   apps.companies.modelsr   apps.calls.modelsr   apps.userprofile.servicesr   UserModelSerializerr	   r   r   r   <module>rT      s0    & . 1 " 5J
!<!< J
r   