
    :EiI                     `    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
 d dlmZ  G d d      Zy)	    )action)Responsestatus)get_company_usersaggregate_user_callsformat_best_worstformat_user_performance)ValidationErrorc                       e Zd ZdZd Zd Z eddgd      d        Z eddgd	      d
        Z eddgd      d        Z	y)UserPerformanceMixinz6
    Enterprise-grade user performance endpoints.
    c                 J    t        |j                        }|t        d      |S )NzNo active company found)r   userr   )selfrequestuserss      J/var/www/html/dp2/backend_v2.1/server/apps/calls/views/user_performance.py_get_company_users_or_400z.UserPerformanceMixin._get_company_users_or_400   s&    !',,/=!";<<    c                 |    | j                  | j                               }| j                  |      }t        ||      S )N)calls_qscompany_users)filter_querysetget_querysetr   r   )r   r   r   r   s       r   
_aggregatezUserPerformanceMixin._aggregate   s>    ''(9(9(;<66w?#'
 	
r   Fgetzuser-performance)detailmethodsurl_pathc                 t    | j                  |      \  }}t        t        ||      t        j                        S )Nr   )r   r   r
   r   HTTP_200_OKr   r   statsr   s       r   user_performancez%UserPerformanceMixin.user_performance!   s4    w/u#E51%%
 	
r   zbest-performing-usersc                 |    | j                  |      \  }}t        dt        ||d      it        j                        S )Ndatacalls_attendedorder_byr   r   r   r	   r   r!   r"   s       r   best_performing_usersz*UserPerformanceMixin.best_performing_users)   sD    w/u!2%"
  %%	' 	'r   zworst-performing-usersc                 |    | j                  |      \  }}t        dt        ||d      it        j                        S )Nr&   calls_missedr(   r   r*   r"   s       r   worst_performing_usersz+UserPerformanceMixin.worst_performing_users2   sD    w/u!2#"
  %%	' 	'r   N)
__name__
__module____qualname____doc__r   r   r   r$   r+   r.    r   r   r   r      st    
 55'4FG
 H
 55'4KL' M' 55'4LM' N'r   r   N)rest_framework.decoratorsr   rest_framework.responser   rest_frameworkr   apps.calls.servicesr   r   r	   r
   rest_framework.exceptionsr   r   r3   r   r   <module>r9      s'    , , !  6+' +'r   