o
    l>j                     @  s   d Z ddlmZ ddlZddlmZmZmZmZ ddl	m
Z
mZmZmZmZmZmZmZmZ ddlmZmZmZmZ eeZG dd deZG d	d
 d
eZG dd dZdS )z8
Low-level CloudKit client for the Reminders container.
    )annotationsN)DictListNoReturnOptional)	CKLookupResponseCKModifyOperationCKModifyResponseCKQueryObjectCKQueryResponseCKZoneChangesResponseCKZoneChangesZoneReqCKZoneIDReqCloudKitExtraMode)CloudKitApiErrorCloudKitAuthErrorCloudKitContainerClientCloudKitRateLimitedc                   @  s   e Zd ZdZdS )RemindersAuthErrorz!Auth/PCS/cookie issues (401/403).N)__name__
__module____qualname____doc__ r   r   W/home/thesage/.local/lib/python3.10/site-packages/pyicloud/services/reminders/client.pyr      s    r   c                      s$   e Zd ZdZd	d
 fddZ  ZS )RemindersApiErrorzCatch-all API error.NmessagestrpayloadOptional[object]c                   s   t  | || _d S N)super__init__r   )selfr   r   	__class__r   r   r"   &   s   
zRemindersApiError.__init__r    )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dd=d
dZed>ddZd?ddZddddd@d#d$Zd%d&dAd)d*Z	dd+dBd/d0Z
dd1dCd7d8ZdDd;d<ZdS )ECloudKitRemindersClientz;
    Raw CloudKit service for the Reminders container.
    N)validation_extrabase_urlr   base_paramsDict[str, object]r(   CloudKitExtraMode | Nonec                C  s    t ||||ddd| _|| _d S )NlowerF)r(   bool_param_stylehandle_rate_limits)r   _client_validation_extra)r#   r)   sessionr*   r(   r   r   r   r"   0   s   
z CloudKitRemindersClient.__init__exc	Exceptionreturnr   c                 C  sd   | j p| }t| trtt| |t| tr"tt| d| jid|t| tr1tt| | j	d| )Nretry_after)r   )
	__cause__
isinstancer   r   r   r   r   r6   r   r   )r3   causer   r   r   _raise_reminders_errorB   s   



z.CloudKitRemindersClient._raise_reminders_errorrecord_names	List[str]zone_idr   r   c              
   C  J   z	| j j||dW S  tttfy$ } z| | W Y d}~dS d}~ww )zFetch records by ID.)r=   N)r0   lookupr   r   r   r:   )r#   r;   r=   r3   r   r   r   r?   O   s   zCloudKitRemindersClient.lookup)desired_keysresults_limitcontinuationqueryr
   r@   Optional[List[str]]rA   Optional[int]rB   Optional[str]r   c             
   C  sP   z| j j|||||dW S  tttfy' } z| | W Y d }~d S d }~ww )N)rC   r=   r@   rA   rB   )r0   rC   r   r   r   r:   )r#   rC   r=   r@   rA   rB   r3   r   r   r   rC   Z   s   	zCloudKitRemindersClient.queryreminderList)record_typerH   
str | Nonec             
   C  s   z| j jt|d|dW S  ty$ } z| | W Y d}~dS d}~w ttfy? } ztjd|d W Y d}~dS d}~ww )zBFetch the current zone sync token using a lightweight query first.)
recordType)rC   r=   Nz,current_sync_token suppressed CloudKit error)exc_info)	r0   query_sync_tokenr
   r   r:   r   r   LOGGERdebug)r#   r=   rH   r3   r   r   r   current_sync_tokenn   s   z*CloudKitRemindersClient.current_sync_token)rA   zone_reqr   r   c             
   C  r>   )z Fetch changes (sync) for a zone.)rP   rA   N)r0   changesr   r   r   r:   )r#   rP   rA   r3   r   r   r   rQ      s   zCloudKitRemindersClient.changes)atomic
operationsList[CKModifyOperation]rR   Optional[bool]r	   c             
   C  sL   z
| j j|||dW S  tttfy% } z| | W Y d}~dS d}~ww )z&Modify (create/update/delete) records.)rS   r=   rR   N)r0   modifyr   r   r   r:   )r#   rS   r=   rR   r3   r   r   r   rV      s   zCloudKitRemindersClient.modifyurlbytesc              
   C  sF   z| j |W S  tttfy" } z| | W Y d}~dS d}~ww )z-Download raw bytes from a CloudKit asset URL.N)r0   download_asset_bytesr   r   r   r:   )r#   rW   r3   r   r   r   rY      s   z,CloudKitRemindersClient.download_asset_bytes)r)   r   r*   r+   r(   r,   )r3   r4   r5   r   )r;   r<   r=   r   r5   r   )rC   r
   r=   r   r@   rD   rA   rE   rB   rF   r5   r   )r=   r   rH   r   r5   rI   )rP   r   rA   rE   r5   r   )rS   rT   r=   r   rR   rU   r5   r	   )rW   r   r5   rX   )r   r   r   r   r"   staticmethodr:   r?   rC   rO   rQ   rV   rY   r   r   r   r   r'   +   s$    

r'   )r   
__future__r   loggingtypingr   r   r   r   pyicloud.common.cloudkitr   r   r	   r
   r   r   r   r   r   pyicloud.common.cloudkit.clientr   r   r   r   	getLoggerr   rM   r4   r   r   r'   r   r   r   r   <module>   s    ,
