
    3fi                       U d dl mZ d dlZd dlmZmZ d dlmZm	Z	m
Z
mZmZmZ e
rd dlmZ eeedej$                  eef   Zded<    G d d	e      Z G d
 dee      Z G d dee      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e      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      Z# G d" d#e#      Z$ G d$ d%e#      Z% G d& d'e      Z& G d( d)      Z'y)*    )annotationsN)ABCabstractmethod)UnionOptionalTYPE_CHECKINGTypeIterator	TypeAlias)Protocolr   
FilterWordc                  h    e Zd ZdZed
d       Zedd       Zd Zd Zed        Z	ed        Z
ddZy	)	QueryBase c                     y Nr   selfs    N/var/www/auto_recruiter/arenv/lib/python3.12/site-packages/O365/utils/query.py	as_paramszQueryBase.as_params           c                     y r   r   r   s    r   renderzQueryBase.render   r   r   c                "    | j                         S r   )__repr__r   s    r   __str__zQueryBase.__str__   s    }}r   c                "    | j                         S r   r   r   s    r   r   zQueryBase.__repr__   s    {{}r   c                     y r   r   r   others     r   __and__zQueryBase.__and__   r   r   c                     y r   r   r!   s     r   __or__zQueryBase.__or__"   r   r   c                N   t        | dd      xs t        | dd      }||j                  |      S t        | dd      }||D ]  }|j                  |      }||c S  yt        | dd      }|9|j                         j                  |j                               rt        | d      S y)a"  
        Returns a filter value by attribute name. It will match the attribute to the start of each filter attribute
        and return the first found.
        
        :param attribute: the attribute you want to search
        :return: The value applied to that attribute or None
        _filter_instanceNfilters_filter_instances
_attribute_word)getattrget_filter_by_attributelower
startswith)r   	attributesearch_object
filter_objresults        r   r-   z!QueryBase.get_filter_by_attribute&   s     07t=OQU/V/xZabfhqswZx$ 88CC5<TCVX\5]$+ "
#;;IF%!M" '.t\4'H$""$//	0ABtW--r   Nreturndictr5   str)r0   r8   r5   Optional[str])__name__
__module____qualname__	__slots__r   r   r   r   r   r#   r%   r-   r   r   r   r   r      sd    I       r   r   c                  <    e Zd ZdZeddd       Zd	dZd
dZddZy)QueryFilterr   Nc                     y r   r   r   	item_names     r   r   zQueryFilter.renderG   r   r   c                &    d| j                         iS )Nz$filterr   r   s    r   r   zQueryFilter.as_paramsK       4;;=))r   c                p   || S t        |t              rt        d| |g      S t        |t              rt	        | |      S t        |t
              rt        d      t        |t              rt	        | |      S t        |t              rt	        | |      S t        dt        |       dt        |              )Nand)r(   order_by2Can't mix search with filters or order by clauses.)r(   select)r(   expand
Can't mix  with )

isinstancer?   ChainFilterOrderByFilterCompositeFilterSearchFilter
ValueErrorSelectFilterExpandFiltertyper!   s     r   r#   zQueryFilter.__and__N   s    =Ke[)utUm44}-"4%@@|,QRR|,"4>>|,"4>>z$u+fT$ZLIJJr   c                T    t        |t              st        d      t        d| |g      S )NzICan't chain a non-query filter with and 'or' operator. Use 'and' instead.or)rM   r?   rR   rN   r!   s     r   r%   zQueryFilter.__or___   s)    %-hii4$//r   r   rB   r9   r5   r8   r4   r"   Optional[QueryBase]r5   r   )r"   r?   r5   rN   )	r:   r;   r<   r=   r   r   r   r#   r%   r   r   r   r?   r?   D   s)    I *K"0r   r?   c                      e Zd ZdZddZy)OperationQueryFilter
_operationc                    || _         y r   r]   )r   	operations     r   __init__zOperationQueryFilter.__init__h   s	    (r   N)r`   r8   r:   r;   r<   r=   ra   r   r   r   r\   r\   e   s    I)r   r\   c                  8     e Zd ZdZd fdZdddZdddZ xZS )	LogicalFilterr^   r*   r+   c                @    t         |   |       || _        || _        y r   )superra   r*   r+   )r   r`   r0   word	__class__s       r   ra   zLogicalFilter.__init__o   s    #(
r   c                ^    |r | j                   | S | d| j                    S | j                   S )N/)r*   rA   s     r   _prepare_attributez LogicalFilter._prepare_attributet   s7    &#%#Adoo%677??"r   c                \    | j                  |       d| j                   d| j                   S N )rl   r^   r+   rA   s     r   r   zLogicalFilter.render~   s.    )))45Qt6GqUUr   )r`   r8   r0   r8   rh   r8   r   )rB   r8   r5   r8   rX   )r:   r;   r<   r=   ra   rl   r   __classcell__ri   s   @r   rd   rd   l   s    5I
#V Vr   rd   c                      e Zd ZdZdddZy)FunctionFilterre   Nc                ^    | j                    d| j                  |       d| j                   dS )N(z, ))r^   rl   r+   rA   s     r   r   zFunctionFilter.render   s1    //"!D$;$;I$F#Gr$**UVWWr   r   rX   r:   r;   r<   r=   r   r   r   r   rs   rs      s    5IXr   rs   c                  4     e Zd ZdZddd fdZdddZ xZS )	IterableFilter)r^   _collection
_item_namer'   arB   c               N    t         |   |       || _        || _        || _        y r   )rg   ra   rz   r{   r'   )r   r`   
collectionfilter_instancerB   ri   s        r   ra   zIterableFilter.__init__   s'    # *(-<r   c                    | j                   j                  | j                        }| j                   d| j                   d| j                   d| dS )Nr}   rk   ru   z: rv   )r'   r   r{   rz   r^   )r   rB   filter_instance_renders      r   r   zIterableFilter.render   sS    !%!6!6!=!=!=!X""#1T__$5Qt6GrJ`Iaabccr   )r`   r8   r   r8   r   r?   rB   r8   r   rX   r:   r;   r<   r=   ra   r   rp   rq   s   @r   ry   ry      s    OIjm =d dr   ry   c                  .     e Zd ZdZd fdZdddZ xZS )rN   )r^   r)   c                >    |dv sJ t         |   |       || _        y )N)rF   rW   )rg   ra   r)   )r   r`   filter_instancesri   s      r   ra   zChainFilter.__init__   s&    M)))#4Dr   c                    d| j                    dj                  | j                  D cg c]  }|j                  |       c}      S c c}w rn   )r^   joinr)   r   )r   rB   fis      r   r   zChainFilter.render   s>    4??#1%**4KaKa+bRBIIi,@+bcc+bs   A)r`   r8   r   zlist[QueryFilter]r   rX   r   rq   s   @r   rN   rN      s    3IE
d dr   rN   c                      e Zd ZdZddZy)ModifierQueryFilterr'   c                    || _         y r   r   )r   r   s     r   ra   zModifierQueryFilter.__init__   s
    -<r   N)r   r?   rb   r   r   r   r   r      s    %I=r   r   c                      e Zd ZdZdddZy)NegateFilterr   Nc                @    d| j                   j                  |       S )Nznot r}   r'   r   rA   s     r   r   zNegateFilter.render   s$    d++22Y2GHIIr   r   rX   rw   r   r   r   r   r      s    %IJr   r   c                      e Zd ZdZdddZy)GroupFilterr   Nc                B    d| j                   j                  |       dS )Nru   r}   rv   r   rA   s     r   r   zGroupFilter.render   s&    4((//)/DEQGGr   r   rX   rw   r   r   r   r   r      s    %IHr   r   c                  D    e Zd ZdZd	d
dZdddZddZddZddZddZ	y)rQ   _searchNc                D    |r|r| d| | _         y || _         y d| _         y )N: r   )r   rh   r0   s      r   ra   zSearchFilter.__init__   s(    '0k4&$9$( "DLr   c                "    | d| d| | _         y rn   r   )r   
search_one
search_twooperators       r   _combinezSearchFilter._combine   s    $Qxj*>r   c                "    d| j                    dS )N"r   r   s    r   r   zSearchFilter.render   s    4<<.""r   c                &    d| j                         iS )Nz$searchr   r   s    r   r   zSearchFilter.as_params   rD   r   c                   || S t        |t              r:| j                         }|j                  | j                  |j                  d       |S t        |t
              rt        d      t        |t              rt        d      t        |t              rt        | |      S t        |t              rt        | |      S t        dt        |       dt        |              )	NrF   r   z&Can't mix search with filters clauses.z'Can't mix search with order by clauses.)searchrI   )r   rJ   rK   rL   )rM   rQ   ri   r   r   r?   rR   rO   rS   rP   rT   rU   r   r"   
new_searchs      r   r#   zSearchFilter.__and__   s    =Ke\*)JemmeL{+EFF}-FGG|,"$u==|,"$u==z$u+fT$ZLIJJr   c                    t        |t              st        d      | j                         }|j	                  | j
                  |j
                  d       |S )NzJCan't chain a non-search filter with and 'or' operator. Use 'and' instead.rW   r   )rM   rQ   rR   ri   r   r   r   s      r   r%   zSearchFilter.__or__   sG    %.ijj^^%
DLL%--$Gr   )NN)rh   zOptional[Union[str, int, bool]]r0   r9   )rF   )r   r8   r   r8   r   r8   r7   r4   rY   )r"   r   r5   rQ   )
r:   r;   r<   r=   ra   r   r   r   r#   r%   r   r   r   rQ   rQ      s&    I#?#*K$r   rQ   c                  H    e Zd ZdZd Zd
dZdddZddZddZddZ	ddZ
y	)rO   _orderbyc                    g | _         y r   r   r   s    r   ra   zOrderByFilter.__init__   s	    02r   c                L    | j                   D cg c]  \  }}|	 c}}S c c}}w r   r   )r   attascs      r   _sorted_attributesz OrderByFilter._sorted_attributes   s    $(MM2S222s    c                ~    |st        d      || j                         vr| j                  j                  ||f       y y )NzAttribute can't be empty)rR   r   r   append)r   r0   	ascendings      r   addzOrderByFilter.add   s>    788D3355MM  )Y!78 6r   c                F    dj                  d | j                  D              S )N,c              3  T   K   | ]   \  }}| d |rdnd j                          " yw)ro   r   descN)strip).0r   r   s      r   	<genexpr>z'OrderByFilter.render.<locals>.<genexpr>   s-     _XS#3%qs 78>>@_s   &()r   r   r   s    r   r   zOrderByFilter.render   s    xx_QUQ^Q^___r   c                &    d| j                         iS )Nz$orderbyr   r   s    r   r   zOrderByFilter.as_params   s    DKKM**r   c                   || S t        |t              r^| j                         }| j                  D ]  \  }}|j	                  ||        |j                  D ]  \  }}|j	                  ||        |S t        |t
              rt        d      t        |t              rt        | |      S t        |t              rt        | |      S t        |t              rt        | |      S t        dt        |       dt        |              )Nz'Can't mix order by with search clauses.)rG   r(   )rG   rI   )rG   rJ   rK   rL   )rM   rO   ri   r   r   rQ   rR   r?   rP   rS   rT   rU   )r   r"   new_order_byr   r   s        r   r#   zOrderByFilter.__and__   s    =Ke]+>>+L MM +S  c*+!NN +S  c*+|,FGG{+"D%@@|,"D??|,"D??z$u+fT$ZLIJJr   c                    t        d      )Nz&Orderby clauses are mutually exclusiveRuntimeErrorr!   s     r   r%   zOrderByFilter.__or__  s    CDDr   N)r5   z	list[str])T)r0   r8   r   boolr5   Noner7   r4   rY   )r"   r   )r:   r;   r<   r=   ra   r   r   r   r   r#   r%   r   r   r   rO   rO      s-    I339`+K*Er   rO   c                  P    e Zd ZdZddZddZddZddZddZddZ	ddZ
dd	Zy
)ContainerQueryFilter
_container_keywordc                2    t        |      | _        d| _        y )Nr   )listr   r   )r   argss     r   ra   zContainerQueryFilter.__init__  s    FJ4jr   c                :    | j                   j                  |       y r   )r   r   )r   items     r   r   zContainerQueryFilter.append  s    t$r   c                ,    t        | j                        S r   )iterr   r   s    r   __iter__zContainerQueryFilter.__iter__   s    DOO$$r   c                n    || j                   D cg c]  }t        |t              r|d   n| c}v S c c}w )Nr   )r   rM   tuple)r   r0   r   s      r   __contains__z!ContainerQueryFilter.__contains__#  s4    VZVeVefd
4(?T!WTIffffs   2c                   || S t        |t              rt        | t              s t        |t              rVt        | t              rF | j                  |  }|D ]0  }t        |t              r|d   }n|}||vs |j                  |       2 |S t        |t              rt        d	i | j                  | d|iS t        |t              rt        d	i | j                  | d|iS t        |t              rt        d	i | j                  | d|iS t        |t              rt        d	i | j                  | d|iS t        |t              rt        d	i | j                  | d|iS t        dt        |       dt        |              )
Nr   r(   r   rG   rI   rJ   rK   rL   r   )rM   rS   rT   ri   r   r   r?   rP   r   rQ   rO   rR   rU   )r   r"   new_containerr   r0   s        r   r#   zContainerQueryFilter.__and__&  s`   =Kul+
40N-*T<2P*DNND1M /dE* $QI $IM1!((./ ! {+"MdmmT9e%LMM|,"LdmmT8U%KLL}-"NdmmT:u%MNN|,"LdmmT8U%KLL|,"LdmmT8U%KLLz$u+fT$ZLIJJr   c                    t        d      )NSCan't combine multiple composite filters with an 'or' statement. Use 'and' instead.r   r!   s     r   r%   zContainerQueryFilter.__or__A  s    pqqr   c                8    dj                  | j                        S )Nr   )r   r   r   s    r   r   zContainerQueryFilter.renderD  s    xx((r   c                @    d| j                    | j                         iS )N$)r   r   r   s    r   r   zContainerQueryFilter.as_paramsG  s    DMM?#T[[]33r   Nr   $Union[str, tuple[str, SelectFilter]])r   r   r5   r   )r5   z.Iterator[Union[str, tuple[str, SelectFilter]]])r0   r8   r5   r   rY   )r"   rZ   r7   r4   )r:   r;   r<   r=   ra   r   r   r   r#   r%   r   r   r   r   r   r   r     s2    *I %%gK6r)4r   r   c                  $     e Zd ZdZd fdZ xZS )rS   r   c                ,    t        |   |  d| _        y )NrI   rg   ra   r   r   r   ri   s     r   ra   zSelectFilter.__init__N      $%r   )r   r8   )r:   r;   r<   r=   ra   rp   rq   s   @r   rS   rS   K  s    *I& &r   rS   c                  ,     e Zd ZdZd fdZddZ xZS )rT   r   c                ,    t        |   |  d| _        y )NrJ   r   r   s     r   ra   zExpandFilter.__init__V  r   r   c                    g }| j                   D ]O  }t        |t              r,|j                  |d    d|d   j	                          d       ?|j                  |       Q dj                  |      S )Nr   z	($select=   rv   r   )r   rM   r   r   r   r   )r   rendersr   s      r   r   zExpandFilter.renderZ  sj    OO 	%D$&$q')DGNN4D3EQGHt$		%
 xx  r   r   r7   r   rq   s   @r   rT   rT   S  s    *I&!r   rT   c                      e Zd ZdZdZdddddd	 	 	 	 	 ddZddZedd       Zedd       Z	edd       Z
edd	       Zedd
       ZddZedd       ZddZddZddZy)rP   z1 A Query object that holds all query parameters. r(   r   rG   rI   rJ   Nc               J    || _         || _        || _        || _        || _        y r   r   )r   r(   r   rG   rI   rJ   s         r   ra   zCompositeFilter.__init__i  s'     /6.419.4.4r   c                   d| j                   r| j                   j                         nd d| j                  r| j                  j                         nd d| j                  r| j                  j                         nd d| j                  r| j                  j                         nd d| j
                  r| j
                  j                          
S d 
S )Nz	Filters: r   z	
Search: z

OrderBy: z	
Select: z	
Expand: )r(   r   r   rG   rI   rJ   r   s    r   r   zCompositeFilter.renderr  s    ++-2F G/3{{t{{))+C D26--,,.RH I/3{{t{{))+C D/3{{t{{))+C	E	

 ACC	E	
r   c                    | j                   duS )z, Returns if this CompositeFilter has filtersNr(   r   s    r   has_filterszCompositeFilter.has_filters{  s     ||4''r   c                    | j                   duS )z, Returns if this CompositeFilter has selectsNrI   r   s    r   has_selectszCompositeFilter.has_selects       {{$&&r   c                    | j                   duS )z, Returns if this CompositeFilter has expandsNrJ   r   s    r   has_expandszCompositeFilter.has_expands  r   r   c                    | j                   duS )z+ Returns if this CompositeFilter has searchNr   r   s    r   
has_searchzCompositeFilter.has_search  r   r   c                    | j                   duS )z- Returns if this CompositeFilter has order_byNrG   r   s    r   has_order_byzCompositeFilter.has_order_by  s     }}D((r   c                    d| _         y)z$ Removes all filters from the query Nr   r   s    r   clear_filterszCompositeFilter.clear_filters  s	    r   c                    | j                   duxr> | j                  du xr. | j                  du xr | j                  du xr | j                  du S )z$ Returns true if it only has filtersNr   r   s    r   has_only_filtersz CompositeFilter.has_only_filters  s^     D( VT[[D-@ V%V*.++*=VBF++QUBU	Wr   c                   i }| j                   r)|j                  | j                   j                                | j                  r)|j                  | j                  j                                | j                  r)|j                  | j                  j                                | j
                  r)|j                  | j
                  j                                | j                  r)|j                  | j                  j                                |S r   )r(   updater   r   rG   rJ   rI   )r   paramss     r   r   zCompositeFilter.as_params  s    <<MM$,,0023;;MM$++//12==MM$--1134;;MM$++//12;;MM$++//12r   c                f   || S t        | j                  | j                  | j                  | j                  | j
                        }t        |t              rB| j                  t        d      |j                  r|j                  |z  |_        |S ||_        |S t        |t              rB| j                  t        d      |j                  r|j                  |z  |_        |S ||_        |S t        |t              rN| j                  | j                  t        d      |j                  r|j                  |z  |_        |S ||_        |S t        |t              r+|j                  r|j                  |z  |_        |S ||_        |S t        |t              r+|j
                  r|j
                  |z  |_        |S ||_        |S t        |t               ra| j                  r|j                  s0|j                  s$|j                  r#| j                  s| j                  rt        d      |j                  r|j                  |j                  z  n|j                  |_        |j                  r|j                  |j                  z  n|j                  |_        |j                  r|j                  |j                  z  n|j                  |_        |j                  r|j                  |j                  z  n|j                  |_        |j
                  r|j
                  |j
                  z  n|j
                  |_        |S )z< Combine this CompositeFilter with another QueryBase object r   rH   )rP   r(   r   rG   rI   rJ   rM   r?   rR   rO   rQ   rS   rT   )r   r"   ncs      r   r#   zCompositeFilter.__and__  s   =KT\\$++PTP]P]$(KKEe[){{& !UVV/1zze+BJ, 	- @EBJ, 	+ }-{{& !UVV13"++-BK$ 	% CHBK$ 	# |,||'4==+D !UVV-/YY		E)BI 	 =BBI 	 |,-/YY		E)BI 	 =BBI 	 |,-/YY		E)BI 	 =BBI 	 /%..,,DLLDMM !UVV79zzemm3u}}BJ46II		ELL05<<BI:<++"++65>>BK46II		ELL05<<BI46II		ELL05<<BI	r   c                    t        |t              r;| j                  r/|j                  r#t        | j                  |j                  z        S t	        d      )Nr   r   )rM   rP   r   r(   r   r!   s     r   r%   zCompositeFilter.__or__  sA    e_-$$)?)?&t||emm/KLLpqqr   )
r(   zOptional[QueryFilter]r   zOptional[SearchFilter]rG   zOptional[OrderByFilter]rI   zOptional[SelectFilter]rJ   zOptional[ExpandFilter]r7   )r5   r   )r5   r   r4   )r"   rZ   r5   rP   )r:   r;   r<   __doc__r=   ra   r   propertyr   r   r   r   r   r   r   r   r#   r%   r   r   r   rP   rP   d  s    ;EI;?bf59\`26525CY5/5
 ( ( ' ' ' ' ' ' ) ) W W
Brr   rP   c            	      >   e Zd Zddddddddd	Zd)d
Zd*dZd+dZd,dZd-dZd-dZ	d-dZ
d-dZd-dZd-dZd,dZd-dZd-dZd-dZdd	 	 	 d.dZddd/dZddd/dZed0d       Zddd1d Zddd2d!Zddd2d"Zed0d#       Zd3d4d%Zed5d&       Zd6d'Zd3d7d(Zy$)8QueryBuilderzfrom/emailAddress/addressz!toRecipients/emailAddress/addresszstart/DateTimezend/DateTimezduedatetime/DateTimezreminderdatetime/DateTimezflag/flagStatuszbody/content)fromtostartendduereminderflagbodyc                L    t        |t              r |       | _        y|| _        y)z Build a query to apply OData filters
        https://docs.microsoft.com/en-us/graph/query-parameters

        :param Protocol protocol: protocol to retrieve the timezone from
        N)rM   rU   protocol)r   r  s     r   ra   zQueryBuilder.__init__  s     '14&@
hr   c                   t        |t              rd| d}|S t        |t              rt        |      j                         }|S |d}|S t        |t        j
                        r_t        |t        j                        r2|j                  &|j                  | j                  j                        }|j                          }|S t        |      }|S )z+ Converts the word parameter into a string 'null)tzinfo)rM   r8   r   r.   dtdatedatetimer  replacer  timezone	isoformat)r   rh   parsed_words      r   _parse_filter_wordzQueryBuilder._parse_filter_word  s    dC dV1+K   d#d)//+K  \ K  bgg&$,;;&<<t}}/E/E<FD!^^-.K  d)Kr   c                   | j                   j                  |      }|rIdj                  |j                  d      D cg c]  }| j                  j                  |       c}      }|S | j                  j                  |      }|S c c}w )a5  
        Look up the provided attribute into the query builder mapping
        Applies a conversion to the appropriate casing defined by the protocol.

        :param attribute: attribute to look up
        :return: the attribute itself of if found the corresponding complete attribute in the mapping
        rk   )_attribute_mappinggetr   splitr  convert_case)r   r0   mappingsteps       r   _get_attribute_from_mappingz(QueryBuilder._get_attribute_from_mapping  s~     ))--i8s#%d++D1 %&I
  229=I	%s   "Bc                p    t        || j                  |      | j                  |            }t        |      S )aC   Apply a logical operation like equals, less than, etc.

        :param operation: how to combine with a new one
        :param attribute: attribute to compare word with
        :param word: value to compare the attribute with
        :return: a CompositeFilter instance that can render the OData logical operation
        r   )rd   r&  r  rP   )r   r`   r0   rh   logical_filters        r   logical_operationzQueryBuilder.logical_operation  s:     'y'+'G'G	'R'+'>'>t'DF ~66r   c                (    | j                  d||      S )z Return an equals check

        :param attribute: attribute to compare word with
        :param word: word to compare with
        :return: a CompositeFilter instance that can render the OData this logical operation
        eqr)  r   r0   rh   s      r   equalszQueryBuilder.equals       %%dIt<<r   c                (    | j                  d||      S )z Return an unequal check

        :param attribute: attribute to compare word with
        :param word: word to compare with
        :return: a CompositeFilter instance that can render the OData this logical operation
        ner,  r-  s      r   unequalzQueryBuilder.unequal&  r/  r   c                (    | j                  d||      S )z Return a 'greater than' check

        :param attribute: attribute to compare word with
        :param word: word to compare with
        :return: a CompositeFilter instance that can render the OData this logical operation
        gtr,  r-  s      r   greaterzQueryBuilder.greater/  r/  r   c                (    | j                  d||      S )z Return a 'greater than or equal to' check

        :param attribute: attribute to compare word with
        :param word: word to compare with
        :return: a CompositeFilter instance that can render the OData this logical operation
        ger,  r-  s      r   greater_equalzQueryBuilder.greater_equal8  r/  r   c                (    | j                  d||      S )z Return a 'less than' check

        :param attribute: attribute to compare word with
        :param word: word to compare with
        :return: a CompositeFilter instance that can render the OData this logical operation
        ltr,  r-  s      r   lesszQueryBuilder.lessA  r/  r   c                (    | j                  d||      S )z Return a 'less than or equal to' check

        :param attribute: attribute to compare word with
        :param word: word to compare with
        :return: a CompositeFilter instance that can render the OData this logical operation
        ler,  r-  s      r   
less_equalzQueryBuilder.less_equalJ  r/  r   c                p    t        || j                  |      | j                  |            }t        |      S )aA   Apply a function operation

        :param operation: function name to operate on attribute
        :param attribute: the name of the attribute on which to apply the function
        :param word: value to feed the function
        :return: a CompositeFilter instance that can render the OData function operation
        r   )rs   r&  r  rP   )r   r`   r0   rh   function_filters        r   function_operationzQueryBuilder.function_operationS  s:     ))-)I)I))T)-)@)@)FH 77r   c                (    | j                  d||      S )a   Adds a contains word check

        :param attribute: the name of the attribute on which to apply the function
        :param word: value to feed the function
        :return: a CompositeFilter instance that can render the OData function operation
        containsrA  r-  s      r   rC  zQueryBuilder.contains`       &&z9dCCr   c                (    | j                  d||      S )a   Adds a startswith word check

        :param attribute: the name of the attribute on which to apply the function
        :param word: value to feed the function
        :return: a CompositeFilter instance that can render the OData function operation
        r/   rD  r-  s      r   r/   zQueryBuilder.startswithi  s     &&|YEEr   c                (    | j                  d||      S )a   Adds a endswith word check

        :param attribute: the name of the attribute on which to apply the function
        :param word: value to feed the function
        :return: a CompositeFilter instance that can render the OData function operation
        endswithrD  r-  s      r   rH  zQueryBuilder.endswithr  rE  r   r|   r}   c               j    t        || j                  |      |j                  |      }t        |      S )aV   Performs the provided filter operation on a collection by iterating over it.

        For example:

        .. code-block:: python

            q.iterable(
                operation='any',
                collection='email_addresses',
                filter_instance=q.equals('address', 'george@best.com')
            )

        will transform to a filter such as:
        emailAddresses/any(a:a/address eq 'george@best.com')

        :param operation: the iterable operation name
        :param collection: the collection to apply the iterable operation on
        :param filter_instance: a CompositeFilter instance on which you will apply the iterable operation
        :param item_name: the name of the collection item to be used on the filter_instance
        :return: a CompositeFilter instance that can render the OData iterable operation
        r}   r   )ry   r&  r(   rP   )r   r`   r   r   rB   iterable_filters         r   iterable_operationzQueryBuilder.iterable_operation{  s7    . ))-)I)I*)U)8)@)@3<> 77r   c               ,    | j                  d|||      S )a   Performs a filter with the OData 'any' keyword on the collection

        For example:
        q.any(collection='email_addresses', filter_instance=q.equals('address', 'george@best.com'))

        will transform to a filter such as:

        emailAddresses/any(a:a/address eq 'george@best.com')

        :param collection: the collection to apply the iterable operation on
        :param filter_instance: a CompositeFilter Instance on which you will apply the iterable operation
        :param item_name: the name of the collection item to be used on the filter_instance
        :return: a CompositeFilter instance that can render the OData iterable operation
        anyr   r   rB   rK  r   r   r   rB   s       r   rM  zQueryBuilder.any  (      &&u7FR[ ' ] 	]r   c               ,    | j                  d|||      S )a   Performs a filter with the OData 'all' keyword on the collection

        For example:
        q.all(collection='email_addresses', filter_instance=q.equals('address', 'george@best.com'))

        will transform to a filter such as:

        emailAddresses/all(a:a/address eq 'george@best.com')

        :param collection: the collection to apply the iterable operation on
        :param filter_instance: a CompositeFilter Instance on which you will apply the iterable operation
        :param item_name: the name of the collection item to be used on the filter_instance
        :return: a CompositeFilter instance that can render the OData iterable operation
        allrN  rO  rP  s       r   rS  zQueryBuilder.all  rQ  r   c                F    t        | j                        }t        |      S )z Apply a not operator to the provided QueryFilter
        :param filter_instance: a CompositeFilter instance
        :return: a CompositeFilter with its filter negated
        )r   r   )r   r(   rP   )r   negate_filters     r   negatezQueryBuilder.negate  s     %_5L5LM}55r   F)groupc                   t        ||D cg c]  }|j                   c}      }t        |      }|r| j                  |      S |S c c}w )N)r`   r   r   )rN   r(   rP   rW  )r   r   rW  r   flchains         r   _chainzQueryBuilder._chain  sG    hWgAhQS"**Ahi.::e$$L Bis   A
c               .     | j                   dg|d|iS )a2   Start a chain 'and' operation

        :param filter_instances: a list of other CompositeFilter you want to combine with the 'and' operation
        :param group: will group this chain operation if True
        :return: a CompositeFilter with the filter instances combined with an 'and' operation
        rF   rW  r[  r   rW  r   s      r   	chain_andzQueryBuilder.chain_and  s      t{{5A#3A5AAr   c               .     | j                   dg|d|iS )aU   Start a chain 'or' operation. Will automatically apply a grouping.

        :param filter_instances: a list of other CompositeFilter you want to combine with the 'or' operation
        :param group: will group this chain operation if True
        :return: a CompositeFilter with the filter instances combined with an 'or' operation
        rW   rW  r]  r^  s      r   chain_orzQueryBuilder.chain_or  s      t{{4@"2@%@@r   c                D    t        | j                        }t        |      S )z4 Applies a grouping to the provided filter_instance r   )r   r(   rP   )r   group_filters     r   rW  zQueryBuilder.group  s     #?#:#:;|44r   Nc                |    | j                  |      }|r| j                  |      }t        ||      }t        |      S )a  
        Perform a search.
        Note from graph docs:

         You can currently search only message and person collections.
         A $search request returns up to 250 results.
         You cannot use $filter or $orderby in a search request.

        :param word: the text to search
        :param attribute: the attribute to search the word on
        :return: a CompositeFilter instance that can render the OData search operation
        )rh   r0   r   )r  r&  rQ   rP   )r   rh   r0   r   s       r   r   zQueryBuilder.search  s>     &&t,88CI49=f--r   c                     t               }| D ]W  }t        |t              r|j                  |       %t        |t              r|j                  |d   |d          Nt        d       t        |      S )av  
        Returns an 'order by' query param
        This is useful to order the result set of query from a resource.
        Note that not all attributes can be sorted and that all resources have different sort capabilities

        :param attributes: the attributes to orderby
        :return: a CompositeFilter instance that can render the OData order by operation
        r   r   zYArguments must be attribute strings or tuples of attribute strings and ascending booleansr   )rO   rM   r8   r   r   rR   rP   )
attributesr   order_by_clauses      r   orderbyzQueryBuilder.orderby  sz     %) 	QO/3/  1OU3  !3_Q5GH  "P Q Q	Q 55r   c                    t               }|D ]^  }| j                  j                  |      }|j                         dv r| j                  j                  d    d| }|j                  |       ` t        |      S )ad  
        Returns a 'select' query param
        This is useful to return a limited set of attributes from a resource or return attributes that are not
        returned by default by the resource.

        :param attributes: a tuple of attribute names to select
        :return: a CompositeFilter instance that can render the OData select operation
        )meetingmessagetypeevent_message_typerk   r   )rS   r  r#  r.   keyword_data_storer   rP   )r   rf  rI   r0   s       r   rI   zQueryBuilder.select  s{     # 	%I229=I $::#}}??@TUVVWXaWbc	MM)$		%
 f--r   c                    t               }|dk(  r| j                  j                  d       d}||j                  ||j                  f       n|j                  |       t        |      S )a  
        Returns an 'expand' query param
        Important: If the 'expand' is a relationship (e.g. "event" or "attachments"), then the ApiComponent using
        this query should know how to handle the relationship (e.g. Message knows how to handle attachments,
        and event (if it's an EventMessage).
        Important: When using expand on multi-value relationships a max of 20 items will be returned.

        :param relationship: a relationship that will be expanded
        :param select: a CompositeFilter instance to select attributes on the expanded relationship
        :return: a CompositeFilter instance that can render the OData expand operation
        eventrk  z/eventr   )rT   r  get_service_keywordr   rI   rP   )r   relationshiprI   rJ   s       r   rJ   zQueryBuilder.expand"  sc     7""mm??@TUVV\]LMM<78MM,'f--r   )r  zUnion[Protocol, Type[Protocol]])rh   r   r5   r8   )r0   r8   r5   r8   )r`   r8   r0   r8   rh   r   r5   rP   )r0   r8   rh   r   r5   rP   )
r`   r8   r   r8   r   rP   rB   r8   r5   rP   )r   r8   r   rP   rB   r8   r5   rP   )r   rP   r5   rP   )r   r8   r   rP   rW  r   r5   rP   )r   rP   rW  r   r5   rP   r   )rh   zUnion[str, int, bool]r0   r9   r5   rP   )rf  z#tuple[Union[str, tuple[str, bool]]]r5   rP   )rf  r8   r5   rP   )rp  r8   rI   zOptional[CompositeFilter]r5   rP   )r:   r;   r<   r   ra   r  r&  r)  r.  r2  r5  r8  r;  r>  rA  rC  r/   rH  rK  rM  rS  staticmethodrV  r[  r_  ra  rW  r   rh  rI   rJ   r   r   r   r  r    s    ,1!%/!	O,"7======8DFD 038),87F8< Z] ]( Z] ]& 6 6 W\  KP B JO A 5 5
.& 6 6(.".r   r  )(
__future__r   r  r  abcr   r   typingr   r   r   r	   r
   r   O365.connectionr   r8   r   r  intfloatr   __annotations__r   r?   r\   rd   rs   ry   rN   r   r   r   rQ   rO   r   rS   rT   rP   r  r   r   r   <module>ry     s+   "  # L L(c4rwwUBC
I C4 4n0)S 0B); )V( V,X] Xd) d	d& 	d=+s =J& JH% H,9 ,^+EI +E\249 24j&' &!' !"mri mr`c. c.r   