
    s0iA                     D    d dl mZmZmZ d dlmZ d dlmZ  G d d      Zy)    )CountAvgQ)TonyCallRepository)timezonec                   $    e Zd ZdZddZd Zd Zy)TonyCallServicez0
    Business logic for TonyCall endpoints.
    Nc                     || _         y N)user)selfr   s     O/var/www/html/dp2/backend_v2.1/server/apps/calls/services/tony_call_services.py__init__zTonyCallService.__init__
   s	    	    c                     | j                   |j                         S | j                   j                  r|S t        | j                   dd      }|r|j	                  |      S |j                         S )z\
        Apply company scoping: superuser sees all, others see only active_company.
        Nactive_company)company)r   noneis_superusergetattrfilter)r   qsr   s      r   scope_queryset_to_userz&TonyCallService.scope_queryset_to_user   s_     9977999!!I ,<dC99^944wwyr   c                 z    |j                  t        d      t        d            }d|j                  d      xs diS )zE
        Compute a small summary for list filtering results.
        idbooking_datetime)total_callsavg_booking_to_call_secondsr   r   )	aggregater   r   get)r   r   datas      r   	summarizezTonyCallService.summarize   sF     ||d(+,>(?  

 488M27a
 	
r   r   )__name__
__module____qualname____doc__r   r   r"    r   r   r	   r	      s     

r   r	   N)	django.db.modelsr   r   r   apps.calls.repositoriesr   django.utilsr   r	   r'   r   r   <module>r+      s    * * 6 !"
 "
r   