U
    ä«Fc+  ã                   @   sT   G d d„ de ƒZG dd„ deƒZG dd„ deƒZG dd„ de ƒZG dd	„ d	e ƒZd
S )c                   @   sà   e Zd ZdZddd„Zdd„ Zdd„ Zed	d
„ ƒZej	dd
„ ƒZedd„ ƒZ
e
j	dd„ ƒZ
edd„ ƒZej	dd„ ƒZedd„ ƒZej	dd„ ƒZedd„ ƒZej	dd„ ƒZedd„ ƒZej	dd„ ƒZedd„ ƒZej	dd„ ƒZdS )ÚStatszP
    Object for building query params for a global email statistics request
    Nc                 C   s8   d| _ d| _d| _d| _d| _d| _d| _|r4|| _dS )z¬Create a Stats object

        :param start_date: Date of when stats should begin in YYYY-MM-DD format, defaults to None
        :type start_date: string, optional
        N)Ú_start_dateÚ	_end_dateÚ_aggregated_byÚ_sort_by_metricÚ_sort_by_directionÚ_limitÚ_offsetÚ
start_date)Úselfr	   © r   ú@/tmp/pip-unpacked-wheel-7j3043uk/sendgrid/helpers/stats/stats.pyÚ__init__   s    zStats.__init__c                 C   s   t |  ¡ ƒS )zJGet a JSON representation of this object.

        :rtype: string
        )ÚstrÚget©r
   r   r   r   Ú__str__   s    zStats.__str__c                 C   s”   i }| j dk	r| j |d< | jdk	r,| j|d< | jdk	r@| j|d< | jdk	rT| j|d< | jdk	rh| j|d< | jdk	r|| j|d< | jdk	r| j|d< |S )	z¤
        Get a JSON-ready representation of Stats

        :returns: This GlobalStats, ready for use in a request body.
        :rtype: response stats dict
        Nr	   Úend_dateÚaggregated_byÚsort_by_metricÚsort_by_directionÚlimitÚoffset)r	   r   r   r   r   r   r   ©r
   Ústatsr   r   r   r      s     













z	Stats.getc                 C   s   | j S )zUDate of when stats should begin in YYYY-MM-DD format

        :rtype: string
        ©r   r   r   r   r   r	   7   s    zStats.start_datec                 C   s
   || _ dS )zšDate of when stats should begin in YYYY-MM-DD format

        :param value: Date representing when stats should begin
        :type value: string
        Nr   ©r
   Úvaluer   r   r   r	   ?   s    c                 C   s   | j S )zSDate of when stats should end in YYYY-MM-DD format

        :rtype: string
        ©r   r   r   r   r   r   H   s    zStats.end_datec                 C   s
   || _ dS )z–Date of when stats should end in YYYY-MM-DD format

        :param value: Date representing when stats should end
        :type value: string
        Nr   r   r   r   r   r   P   s    c                 C   s   | j S )zfChosen period (e.g. 'day', 'week', 'month') for how stats get grouped

        :rtype: string
        ©r   r   r   r   r   r   Y   s    zStats.aggregated_byc                 C   s
   || _ dS )z¨Chosen period (e.g. 'day', 'week', 'month') for how stats get grouped

        :param value: Period for how keys will get formatted
        :type value: string
        Nr   r   r   r   r   r   a   s    c                 C   s   | j S )z8Metric to sort stats by

        :rtype: string
        ©r   r   r   r   r   r   j   s    zStats.sort_by_metricc                 C   s
   || _ dS )zyMetric to sort stats by

        :param value: Chosen metric stats will by sorted by
        :type value: string
        Nr   r   r   r   r   r   r   s    c                 C   s   | j S )zVDirection data will be sorted, either 'asc' or 'desc'

        :rtype: string
        ©r   r   r   r   r   r   {   s    zStats.sort_by_directionc                 C   s
   || _ dS )z›Direction data will be sorted, either 'asc' or 'desc'

        :param value: Direction of data, either 'asc' or 'desc'
        :type value: string
        Nr    r   r   r   r   r   ƒ   s    c                 C   s   | j S )zBMax amount of results to be returned

        :rtype: int
        ©r   r   r   r   r   r   Œ   s    zStats.limitc                 C   s
   || _ dS )zsMax amount of results to be returned

        :param value: Max amount of results
        :type value: int
        Nr!   r   r   r   r   r   ”   s    c                 C   s   | j S )zWNumber of places a starting point of a data set will move

        :rtype: int
        ©r   r   r   r   r   r      s    zStats.offsetc                 C   s
   || _ dS )z¢Number of places a starting point of a data set will move

        :param value: Number of positions to move from starting point
        :type value: int
        Nr"   r   r   r   r   r   ¥   s    )N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   Úpropertyr	   Úsetterr   r   r   r   r   r   r   r   r   r   r      sB    ÿ













r   c                       s>   e Zd ZdZd‡ fdd„	Zdd„ Zedd„ ƒZd	d
„ Z‡  Z	S )ÚCategoryStatszL
    object for building query params for a category statistics request
    Nc                    s>   d| _ tt| ƒ ¡  |r:|r:|| _|D ]}|  t|ƒ¡ q&dS )a7  Create a CategoryStats object

        :param start_date: Date of when stats should begin in YYYY-MM-DD format, defaults to None
        :type start_date: string, optional
        :param categories: list of categories to get results of, defaults to None
        :type categories: list(string), optional
        N)Ú_categoriesÚsuperr)   r   r	   Úadd_categoryÚCategory)r
   r	   Ú
categoriesZcat_name©Ú	__class__r   r   r   ³   s    zCategoryStats.__init__c                 C   s²   i }| j dk	r| j |d< | jdk	r,| j|d< | jdk	r@| j|d< | jdk	rT| j|d< | jdk	rh| j|d< | jdk	r|| j|d< | jdk	r| j|d< | jdk	r®d	d
„ | jD ƒ|d< |S )zw
        Get a JSON-ready representation of this CategoryStats.

        :return: response category stats dict
        Nr	   r   r   r   r   r   r   c                 S   s   g | ]}|  ¡ ‘qS r   ©r   )Ú.0Úcategoryr   r   r   Ú
<listcomp>Ú   s     z%CategoryStats.get.<locals>.<listcomp>r.   )r	   r   r   r   r   r   r   r.   r   r   r   r   r   Ä   s(    














ÿ
zCategoryStats.getc                 C   s   | j S )z;List of categories

        :rtype: list(Category)
        )r*   r   r   r   r   r.   Þ   s    zCategoryStats.categoriesc                 C   s    | j dkrg | _ | j  |¡ dS )z™Appends a category to this object's category list

        :param category: Category to append to CategoryStats
        :type category: Category
        N)r*   Úappend)r
   r3   r   r   r   r,   æ   s    
zCategoryStats.add_category)NN)
r#   r$   r%   r&   r   r   r'   r.   r,   Ú__classcell__r   r   r/   r   r)   ¯   s   
r)   c                       s>   e Zd ZdZd‡ fdd„	Zdd„ Zedd„ ƒZd	d
„ Z‡  Z	S )ÚSubuserStatszJ
    object of building query params for a subuser statistics request
    Nc                    s>   d| _ tt| ƒ ¡  |r:|r:|| _|D ]}|  t|ƒ¡ q&dS )a0  Create a SubuserStats object

        :param start_date: Date of when stats should begin in YYYY-MM-DD format, defaults to None
        :type start_date: string, optional
        :param subusers: list of subusers to get results of, defaults to None
        :type subusers: list(string), optional
        N)Ú	_subusersr+   r7   r   r	   Úadd_subuserÚSubuser)r
   r	   ÚsubusersZsubuser_namer/   r   r   r   õ   s    zSubuserStats.__init__c                 C   s²   i }| j dk	r| j |d< | jdk	r,| j|d< | jdk	r@| j|d< | jdk	rT| j|d< | jdk	rh| j|d< | jdk	r|| j|d< | jdk	r| j|d< | jdk	r®d	d
„ | jD ƒ|d< |S )zu
        Get a JSON-ready representation of this SubuserStats.

        :return: response subuser stats dict
        Nr	   r   r   r   r   r   r   c                 S   s   g | ]}|  ¡ ‘qS r   r1   )r2   Úsubuserr   r   r   r4     s     z$SubuserStats.get.<locals>.<listcomp>r;   )r	   r   r   r   r   r   r   r;   r   r   r   r   r     s(    














ÿ
zSubuserStats.getc                 C   s   | j S )z8List of subusers

        :rtype: list(Subuser)
        )r8   r   r   r   r   r;      s    zSubuserStats.subusersc                 C   s    | j dkrg | _ | j  |¡ dS )z’Appends a subuser to this object's subuser list

        :param subuser: Subuser to append to SubuserStats
        :type subuser: Subuser
        N)r8   r5   )r
   r<   r   r   r   r9   (  s    
zSubuserStats.add_subuser)NN)
r#   r$   r%   r&   r   r   r'   r;   r9   r6   r   r   r/   r   r7   ñ   s   
r7   c                   @   s<   e Zd ZdZd
dd„Zedd„ ƒZejdd„ ƒZdd	„ ZdS )r-   zZ
    Represents a searchable statistics category to be used in a CategoryStats object
    Nc                 C   s   d| _ |dk	r|| _ dS )zCreate a Category object

        :param name: name of category, defaults to None
        :type name: string, optional
        N©Ú_name©r
   Únamer   r   r   r   7  s    zCategory.__init__c                 C   s   | j S )z5Get name of category

        :rtype: string
        r=   r   r   r   r   r@   A  s    zCategory.namec                 C   s
   || _ dS )zqSet name of category

        :param value: name of the statistical category
        :type value: string
        Nr=   r   r   r   r   r@   I  s    c                 C   s   | j S )zj
        Get a string representation of Category.

        :return: string of the category's name
        ©r@   r   r   r   r   r   R  s    zCategory.get)N©	r#   r$   r%   r&   r   r'   r@   r(   r   r   r   r   r   r-   3  s   



r-   c                   @   s<   e Zd ZdZd
dd„Zedd„ ƒZejdd„ ƒZdd	„ ZdS )r:   zM
    Represents a searchable subuser to be used in a SubuserStats object
    Nc                 C   s   d| _ |dk	r|| _ dS )z}Create a Subuser object

        :param name: name of subuser, defaults to None
        :type name: string, optional
        Nr=   r?   r   r   r   r   _  s    zSubuser.__init__c                 C   s   | j S )z8Get name of the subuser

        :rtype: string
        r=   r   r   r   r   r@   i  s    zSubuser.namec                 C   s
   || _ dS )zgSet name of the subuser

        :param value: name of the subuser
        :type value: string
        Nr=   r   r   r   r   r@   q  s    c                 C   s   | j S )zh
        Get a string representation of Subuser.

        :return: string of the subuser's name
        rA   r   r   r   r   r   z  s    zSubuser.get)NrB   r   r   r   r   r:   [  s   



r:   N)Úobjectr   r)   r7   r-   r:   r   r   r   r   Ú<module>   s
    /BB(