
    3fi                     F    d dl Zd dlmZmZmZmZ ddlmZ  G d de      Z	y)    N)IterableMappingOptionalUnion   )ApiComponentc                       e Zd ZdZddiZddd fd
Zddee   defd	Ze		 	 dd
ee
j                     dee   defd       Ze	deeee   f   defd       Z	 	 ddddddddddd	dedee   deeee   f   d
ee
j                     dee   dee   dee   dee   dee   dee   dee   deeeef      dee   fdZdddded
ee
j                     dee   dee   fdZdedefdZ xZS ) Subscriptionsz5Subscription operations for Microsoft Graph webhooks.subscriptionsz/subscriptionsN)parentconc                    |r|rt        d      |r|j                  n|| _        |j                  dd       xs |rt        |dd       nd }t        |   |r|j                  n|j                  d      |       y )Nz*Need a parent or a connection but not bothmain_resourceprotocol)r   r   )
ValueErrorr   popgetattrsuper__init__r   get)selfr   r   kwargsr   	__class__s        P/var/www/auto_recruiter/arenv/lib/python3.12/site-packages/O365/subscriptions.pyr   zSubscriptions.__init__   sv    cIJJ!'6::S

?D9 
6<GFOT2$ 	 	(.V__FJJz4J' 	 	
    subscription_idreturnc                     | j                   j                  d      }|t        d      | j                  j                  j                  d      }|r	| | d| S | | S )z1Build the Microsoft Graph subscriptions endpoint.r   z)Subscriptions endpoint is not configured./)
_endpointsr   r   r   service_urlrstrip)r   r   endpointbase_urls       r   _build_subscription_urlz%Subscriptions._build_subscription_url   sj    ??&&7HII==,,33C8Zz?*;<<H:&&r   expiration_datetimeexpiration_minutesc                    | r|t        d      | e||nd}|dk  rt        d      t        j                  j                  t        j                  j
                        t        j                  |      z   } n`| j                  +| j                  t        j                  j
                        } n)| j                  t        j                  j
                        } | j                  d      j                  d	d
      S )zGReturn an ISO 8601 UTC expiration string as required by Graph webhooks.zCProvide either expiration_datetime or expiration_minutes, not both.<   r   z.expiration_minutes must be a positive integer.)minutes)tzinfomicroseconds)timespecz+00:00Z)r   dtdatetimenowtimezoneutc	timedeltar+   replace
astimezone	isoformat)r&   r'   r*   s      r   _format_subscription_expirationz-Subscriptions._format_subscription_expiration&   s     #5#AU  &,>,J(PRG!| !QRR"$++//"++//"BR\\F # #))1&9&A&A&A&Y#&9&D&DR[[__&U#",,n,EMMhX[\\r   change_typec                 $   t        | t              r| j                         }n?	 | D cg c]  }t        |      j                          }}dj                  d |D              }|st	        d      |S c c}w # t        $ r}t	        d      |d}~ww xY w)zCNormalize changeType into the comma-separated string Graph expects.z7change_type must be a string or an iterable of strings.N,c              3   &   K   | ]	  }|s|  y wN ).0parts     r   	<genexpr>z7Subscriptions._stringify_change_type.<locals>.<genexpr>J   s     <dtT<s   z,change_type must contain at least one value.)
isinstancestrstrip	TypeErrorr   join)r9   valuer@   partsexcs        r   _stringify_change_typez$Subscriptions._stringify_change_type>   s     k3'%%'E7BCtT*CC
 HH<e<<EKLL D  Ms(   A5  A0A5 0A5 5	B>B

B)	r&   r'   client_stateinclude_resource_dataencryption_certificateencryption_certificate_idlifecycle_notification_urllatest_supported_tls_versionadditional_datanotification_urlresourcerK   rL   rM   rN   rO   rP   rQ   c       	   	         |st        d      |xs | j                  }|st        d      |j                  d      sd| }| j                  ||      }| j	                  |      }| j                  d      || j                  d      || j                  d      || j                  d      |i}|||| j                  d
      <   |||| j                  d      <   |||| j                  d      <   |	|	|| j                  d      <   |
|
|| j                  d      <   |||| j                  d      <   |rWt        |t              st        d      |j                  |j                         D ci c]  \  }}t        |      | c}}       | j                         } | j                  j                  |fd|i|}|sy	|j                         S c c}}w )zuCreate a Microsoft Graph webhook subscription.

        See Documentation.md for webhook setup requirements.
        z"notification_url must be provided.zresource must be provided.r   r&   r'   r9   rR   rS   expiration_date_timeNrK   rL   rM   rN   rO   rP   z.additional_data must be a mapping if provided.data)r   r   
startswithr8   rJ   _ccrB   r   updateitemsrC   r%   r   postjson)r   rR   rS   r9   r&   r'   rK   rL   rM   rN   rO   rP   rQ   request_kwargsexpiration_valuechange_type_valuepayloadkeyrG   urlresponses                        r   create_subscriptionz!Subscriptions.create_subscriptionO   s   *  ABB1t119::""3'8*~H?? 31 @ 
 !77D HH]#%6HH'(*:HHZ (HH+,.>	
 #0<GDHH^,- ,9NGDHH456!-:PGDHH567$0=VGDHH89:%1>XGDHH9:;'3 - 78 ow7 !QRRNNo>S>S>UV
UCHeOVW**, 488==E7EnE}} Ws   *G

rU   c                    |st        d      | j                  ||      }| j                  d      |i}| j                  |      } | j                  j
                  |fd|i|}|sy|j                         S )z'Renew an existing webhook subscription.!subscription_id must be provided.rU   rV   rW   N)r   r8   rY   r%   r   patchr]   )	r   r   r&   r'   r^   r_   ra   rc   rd   s	            r   renew_subscriptionz Subscriptions.renew_subscription   s     @AA?? 31 @ 
 HH+,.>
 **?;!488>>#FGF~F}}r   c                     |st        d      | j                  |      } | j                  j                  |fi |}t	        |      S )z(Delete an existing webhook subscription.rg   )r   r%   r   deletebool)r   r   r^   rc   rd   s        r   delete_subscriptionz!Subscriptions.delete_subscription   sF     @AA**?;"488??39.9H~r   r=   )NN)Ncreated)__name__
__module____qualname____doc__r    r   r   rC   r%   staticmethodr/   r0   intr8   r   r   rJ   rl   r   objectdictre   ri   rm   __classcell__)r   s   @r   r
   r
      s   ? 	)J "&4 
'x} 'PS ' 59,0]%bkk2]$SM] 
] ]. E#x}2D,E #  & #'1:	D 6:,0&*040437486::>DD 3-D 3-.	D &bkk2D %SMD smD  (~D !)D $,C=D %-SMD '/smD "'#v+"67D  
$!DT 6:,0 &bkk2	
 %SM 
$: 
	r   r
   )
r0   r/   typingr   r   r   r   utilsr   r
   r>   r   r   <module>rz      s     5 5 wL wr   