
    Owi#                         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	 d dl
mZ d dlmZmZmZmZ  G d d	e      Z G d
 de      Z G d de      Z G d de      Z G d dej*                        Z G d de      Zy)    )models)timezone)BotName)AbstractTimeStampModel)User)Company)BotTypeCRON_JOB_STATUSNotificationTypeCallTimeCategoryc                      e Zd ZdZg dZed   dfed   dfed   dfed   dfgZddgZ ej                  d	d
d
      Z
 ej                  d	      Z ej                  d	      Z ej                  ed      Z ej                  d
 ej                                Z ej                  d	d
d
      Z ej&                  eej*                  d
d
      Z ej&                  eej*                  d
d
      Z ej&                  ed
d
ej*                  d      Z ej                  d	      Z ej6                  d
      Z ej6                  d
d
      Z ej6                  d
      Z ej                  d
 ej                                Z  ej                  d
      Z! ejD                  dd      Z# ejD                  dd      Z$ ej                  d	      Z% ej                  d	      Z& ej6                  d
d
      Z' ejP                  d
d
      Z) ej                  ed      Z* ej                  d
e      Z+ ej&                  eej*                  d
d
d      Z, ejP                  d
d
      Z-d Z.y)CallCall object.))r   zNot Transferred)   Transferred)   zTransfer FailedNOT_PROCESSED
PROCESSING	COMPLETEDFAILED)r   zNo Intent for booking)r   zIntent for booking   T
max_lengthblanknullr   r   )choicesdefault)r   r   	on_deleter   r   calls)r   r   r    related_namer   r   r   r      r   )
max_digitsdecimal_placesr   r   
read_calls)r    r   r   r"   c                 T    d| j                    d| j                   d| j                   S )NzCall  | u    → )call_idfrom_number	to_numberselfs    :/var/www/html/dp2/backend_v2.1/server/apps/calls/models.py__str__zCall.__str__k   s+    t||nC(8(8'9t~~>NOO    N)/__name__
__module____qualname____doc__TRANSFER_STATUS_CHOICESr
   BOOKING_INTENT_STATUS_CHOICESBOOKING_INTENT_CHOICESr   	CharFieldcaller_namer.   r/   SmallIntegerFieldtransfer_statusr   model_choicescall_time_categorytransfer_number
ForeignKeyr   SET_NULLtransfer_userr   company
dealershipstatus	TextField
transcripttranscript_completesummaryr	   bot_type	sentimentDecimalFielddurationcostr-   twilio_call_sidtwilio_recording_textDateTimeFieldbooking_datetimebooking_intentbooking_intent_statusread_byread_atr3    r4   r2   r   r      s    
	)?;		&5		%{3		"H-	%! 	%!
 #&""cDIK"&""c2K   C0I.f..'O 211. ..0 'f&&#TMO%F%%//	M  f//	G #""//J V-F!!!-J*&**DAfT*G'v''%%%'H )((d3I"v""aBH6!A>Df#.G&f&&#6O,F,,4dC+v++TB-V--&N 5F44-  f//!G #f""D9GPr4   r   c                      e Zd ZdZ ej
                  d      Z ej
                  d      Z ej
                  d      Z ej                  d      Z
 ej                  dd      Z ej
                  d      Z ej
                  d      Z ej                  dd      Z ej                   eej$                  dd      Z ej
                  d      Z ej
                  d      Z ej
                  d      Zd Z G d	 d
      Zy)TonyCallr   r   r   Tr#   r)   r   c                      d| j                    S )Nz	TonyCall )r-   r0   s    r2   r3   zTonyCall.__str__}   s    4<<.))r4   c                       e Zd ZdZy)TonyCall.Metavtony_callsN)r5   r6   r7   db_tablerZ   r4   r2   Metar_      s     r4   rb   N)r5   r6   r7   r8   r   r<   
end_reasonr-   recording_urlrI   rJ   rT   call_date_time	intentionrescheduledrU   rC   r   rD   rF   rH   	called_tocalled_numberr3   rb   rZ   r4   r2   r\   r\   n   s    !!!S1Jf#.G$F$$4M!!!-J)V))t4@N   C0I#6##s3K+v++TBf6??UYZGV-F   C0I$F$$4M*! !r4   r\   c                   $   e Zd ZddgZ ej
                  eej                  d      Z ej
                  e	ej                  d      Z
 ej                  de      Z ej                  d	      Z ej                  d
ddd      Z G d d      Zd Zy)CallActivity)READread)PLAYplayed
activitiesr    r"   call_activities
   )r   r   Tr%   r&   r   )r'   r(   r   r   c                       e Zd ZdgZy)CallActivity.Meta-created_atNr5   r6   r7   orderingrZ   r4   r2   rb   ru      	    !?r4   rb   c                     | j                    d| j                  j                          d| j                   d| j                   S )N z at )useractionlowercall
created_atr0   s    r2   r3   zCallActivity.__str__   s:    ))Adkk//12!DII;d4??BSTTr4   N)r5   r6   r7   ACTION_CHOICESr   rC   r   CASCADEr   r   r|   r<   r}   rT   performed_atrO   duration_playedrb   r3   rZ   r4   r2   rk   rk      s    N
 6TV^^,WD6TV^^J[\DV^DF'6''T2L)f))Qqt[_`O# #Ur4   rk   c                      e Zd Z ej                  eej                  d      Z ej                  eej                  dddd      Z	 ej                  dddd	      Z ej                  d
ddd	      Z ej                  ddddd      Z ej                  dd      Z ej                         Z ej"                  d      Z ej&                  dd      Z G d d      Zd Zd Zy)UserMessagereceived_messagesrq   Tmessagesz#The company this message belongs tor    r   r   r"   	help_textr   z<Name of the customer who sent or is related to this message.)r   r   r   r      z<Customer phone number. Store as text to preserve formatting.z!To update record-off-time-message)r   uniquer   r   r   )r   r   Fr   r)   c                       e Zd ZdgZy)UserMessage.Metarv   Nrw   rZ   r4   r2   rb   r      ry   r4   rb   c                     | j                   s5d| _         t        j                         | _        | j	                  ddg       y y NTis_readrY   )update_fieldsr   r   nowrY   saver0   s    r2   mark_as_readzUserMessage.mark_as_read   5    ||DL#<<>DLIIY	$:I; r4   c                 |    d| j                    d| j                  j                  j                   d| j                   S )NzMessage from z to 	 | Read: )customer_name	recipientprofile	full_namer   r0   s    r2   r3   zUserMessage.__str__   s@     2 234>>))334 5( 	)r4   N)r5   r6   r7   r   rC   r   r   r   r   rF   r<   r   customer_numberrR   subjectrI   bodyBooleanFieldr   rT   rY   rb   r   r3   rZ   r4   r2   r   r      s   !!!..(I  f..7G %F$$P	M 'f&&P	O 'f&&5O f#T:G6D!f!!%0G"f""D9G# #<)r4   r   c                      e Zd Z ej                  eej                  d      Z ej                  eej                  dddd      Z	 ej                   ej                         d      Z ej                  eej                  dddd      Z ej"                  ddd	      Z ej&                  dd
      Z ej*                  d      Z ej.                  dd
      Z ej.                  d      Zd Z G d d      Zd Zy)Notificationnotificationsrq   Tz(The company this notification belongs tor   )r   db_indexz9Optional reference to the call this notification is aboutr   r   r$   Fr   )auto_now_addc                     | j                   s5d| _         t        j                         | _        | j	                  ddg       y y r   r   r0   s    r2   r   zNotification.mark_as_read   r   r4   c                   f    e Zd Z ej                  ddg       ej                  ddg      gZdgZy)Notification.Metar   r   )fieldsr   rv   N)r5   r6   r7   r   Indexindexesrx   rZ   r4   r2   rb   r      s8    FLLi 89FLLl ;<

 "?r4   rb   c                     t        | j                  j                  d| j                  j                        }d| d| j                   S )Nr   zNotification to r   )getattrr   r   usernamer   )r1   names     r2   r3   zNotification.__str__   s;    t~~--{DNN<S<ST!$y??r4   N)r5   r6   r7   r   rC   r   r   r   r   rF   r>   r   r@   notification_typer   rD   r   r<   titlerI   messager   r   rT   rY   r   r   rb   r3   rZ   r4   r2   r   r      s   !!!..$I  f..$<G 100. ..0
 6//$MD F4dCEfT5G!f!!%0G"f""D9G%%%48J<# #@r4   r   c                   (   e Zd ZdZ ej
                  eej                  d      Z ej                  d      Z
 ej                  d      Z ej                  dd      Z ej                  d	
      Z ej                  d      Z G d d      Zd Zy)BotInstructionTemplatezi
    Stores all bot dynamic messages & routing instructions in DB.
    No hard-coded text in Python.
    bot_instruction_templatesrq   2   r   d   z;Short admin-friendly name (e.g. 'Default Advisor Transfer'))r   r   z]Use placeholders like:
{advisor_name}, {advisor_phone}, {dealership_name}, {dealership_phone})r   Tr   c                       e Zd ZdZg dZy)BotInstructionTemplate.Meta)rF   bot_nametemplate_typeN)r5   r6   r7   unique_togetherrx   rZ   r4   r2   rb   r   #  s    B;r4   rb   c                 f    | j                   j                   d| j                   d| j                   S )Nr,   )rF   r   r   r   r0   s    r2   r3   zBotInstructionTemplate.__str__'  s/    ,,##$Cc$:L:L9MNNr4   N)r5   r6   r7   r8   r   rC   r   r   rF   r<   r   r   r   rI   contentr   	is_activerb   r3   rZ   r4   r2   r   r     s    
  f..0G  vH %F$$M FOE
 fUG $##D1I< <Or4   r   N)	django.dbr   django.utilsr   apps.companies.constantsr   coresite.mixinr   apps.core.modelsr   apps.companies.modelsr   apps.calls.constantsr	   r
   r   r   r   r\   rk   r   Modelr   r   rZ   r4   r2   <module>r      s     ! , 1 ! ) ]P! ]P~!% !*U) U$3)( 3)j5@6<< 5@n'O3 'Or4   