o
    7i                     @   s   d dl mZ d dlmZ ddlmZmZmZmZm	Z	 e
eG dd dejZe
e	G dd dejZe
eG d	d
 d
ejZe
eG dd dejZe
eG dd dejZdS )    )admin)format_html   )CallCallLog
CallPromptVapiAssistantUserAssistantPreferencec                   @   sx   e Zd Zg dZddgZddgZddgZddgZd	d
difddddffZdd Z	de	_
dd Zde_
dd Zde_
dS )VapiAssistantAdmin)nameassistant_id	is_active
created_at
call_countr   r   r   r   r   activate_assistantsdeactivate_assistantszAssistant Informationfields)r   r   r   
Statistics)r   r   collapser   classesc                 C   s"   |r|j r|j }td|S dS )z0Display number of calls made with this assistantz<strong>{}</strong> callsz0 calls)pkcallscountr   )selfobjr    r   $/var/www/html/philips/calls/admin.pyr      s   


zVapiAssistantAdmin.call_countzTotal Callsc                 C   "   |j dd}| || d dS )z,Admin action to activate selected assistantsTr   z% assistant(s) activated successfully.Nupdatemessage_userr   requestquerysetupdatedr   r   r   r   !      z&VapiAssistantAdmin.activate_assistantszActivate selected assistantsc                 C   r   )z.Admin action to deactivate selected assistantsFr    z' assistant(s) deactivated successfully.Nr!   r$   r   r   r   r   (   r(   z(VapiAssistantAdmin.deactivate_assistantszDeactivate selected assistantsN)__name__
__module____qualname__list_displaylist_filtersearch_fieldsreadonly_fieldsactions	fieldsetsr   short_descriptionr   r   r   r   r   r   r
      s(    

r
   c                   @   s8   e Zd Zg dZddgZg dZdgZdddiffZdS )UserAssistantPreferenceAdmin)user	assistant
updated_atr5   r6   )user__usernameuser__emailassistant__namezPreference Informationr   Nr)   r*   r+   r,   r-   r.   r/   r1   r   r   r   r   r3   0   s    r3   c                       sr   e Zd Zg dZg dZg dZg dZddddfd	d
ddfddddffZdd Zde_	 fddZ
  ZS )CallPromptAdmin)r   r   
is_default
created_byr   r6   )r   r<   r   r6   )r   descriptionprompt_template)r   r6   preview_promptzBasic Information)r   r>   r   r<   r=   z_Set "Is Default" to use this prompt when no prompt is selected. Only one prompt can be default.)r   r>   zPrompt Template)r?   r@   zrUse placeholders: {senior_name}, {senior_age}, {interests}, {health_notes}, {call_purpose}, {conversation_context}
Timestampsr   r6   r   r   c              
   C   s   |r|j s	tdS ddddddd}z|j jdi |}td	|W S  ty: } ztd
t|W  Y d}~S d}~w tyR } ztdt|W  Y d}~S d}~ww )z;Show a preview of how the prompt will look with sample dataz7<em>Enter a prompt template above to see a preview</em>zJohn Doe75zGardening, ReadingzGenerally healthygeneral_checkinz0This is the first conversation with this person.)senior_name
senior_age	interestshealth_notescall_purposeconversation_contextz<pre style="max-height: 300px; overflow-y: auto; white-space: pre-wrap; background-color: #f8f9fa; padding: 10px; border-radius: 4px;">{}</pre>z><span style="color: red;">Error: Missing placeholder {}</span>Nz*<span style="color: red;">Error: {}</span>r   )r?   r   formatKeyErrorstr	Exception)r   r   sample_datapreviewer   r   r   r@   T   s&   
	zCallPromptAdmin.preview_promptzPreview (with sample data)c                    sf   ddl m} |js|j|_|jr(|j}|jjdd}|r"|j	|d}|j
dd t |||| dS )zCSet created_by to current user if not set and handle default promptr   )r   T)r<   )r   FN)modelsr   created_by_idr4   r=   r<   r   objectsfilterexcluder"   super
save_model)r   r%   r   formchanger   
current_pkr&   	__class__r   r   rX   l   s   zCallPromptAdmin.save_model)r)   r*   r+   r,   r-   r.   r/   r1   r@   r2   rX   __classcell__r   r   r\   r   r;   >   s*    r;   c                   @   sf   e Zd Zg dZg dZg dZddgZdddifd	dd
ifdddifddddfddddffZdS )	CallAdmin)seniortwilio_statusr5   promptdurationr   initiated_by)ra   vapi_statusr   rI   rb   r5   )senior__name
twilio_sidvapi_call_idprompt__namer   r6   zCall Informationr   )r`   rI   rb   rd   zTwilio Details)rg   ra   rc   call_start_timecall_end_timezVapi Details)r5   rh   re   vapi_assistant_idzAI Configuration)	ai_promptr   r   rA   rB   Nr:   r   r   r   r   r_      s.    r_   c                   @   sN   e Zd Zg dZddgZddgZdgZdddifd	d
ddfdddiffZdS )CallLogAdmin)call
event_typemessager   rp   r   call__senior__namerq   zLog Informationr   )ro   rp   rq   zAdditional Data)datar   r   	Timestamp)r   Nr:   r   r   r   r   rn      s     rn   N)django.contribr   django.utils.htmlr   rR   r   r   r   r   r	   register
ModelAdminr
   r3   r;   r_   rn   r   r   r   r   <module>   s    )E