
    =[j`:                    >   d Z ddlmZ ddlZddlmZ ddlmZmZmZm	Z	m
Z
mZ ddlmZ ddlmZ ddlmZ d	d
lmZ d	dlmZmZmZ 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"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+  ej,        e-          Z.ee+e"f         Z/ G d de          Z0dS )a  
High-level Reminders service built on top of the iCloud Reminders CloudKit API.

Public API:
  - RemindersService.lists() -> Iterable[RemindersList]
  - RemindersService.reminders(list_id=None) -> Iterable[Reminder]
  - RemindersService.list_reminders(list_id, include_completed=False, results_limit=200)
  - RemindersService.get(reminder_id) -> Reminder
  - RemindersService.sync_cursor() -> str
  - RemindersService.iter_changes(since=None) -> Iterable[ReminderChangeEvent]
  - RemindersService.create(...)
  - RemindersService.update(reminder) -> None
  - RemindersService.delete(reminder) -> None
  - RemindersService.add_location_trigger(reminder, ...) -> tuple[Alarm, LocationTrigger]
  - RemindersService.create_hashtag(...) / update_hashtag(...) / delete_hashtag(...)
  - RemindersService.create_url_attachment(...) / update_attachment(...) / delete_attachment(...)
  - RemindersService.create_recurrence_rule(...) / update_recurrence_rule(...) / delete_recurrence_rule(...)
  - RemindersService.alarms_for(reminder) -> list[AlarmWithTrigger]
  - RemindersService.tags_for(reminder) -> list[Hashtag]
  - RemindersService.attachments_for(reminder) -> list[Attachment]
  - RemindersService.recurrence_rules_for(reminder) -> list[RecurrenceRule]

The service returns typed reminder, list, alarm, attachment, hashtag, and
recurrence models so normal callers do not need to work with CloudKit records
directly.
    )annotationsN)datetime)AnyDictIterableListOptionalUnion)CKRecord)CloudKitExtraMode)BaseService   )RemindersRecordMapper)_decode_crdt_document_encode_crdt_document_generate_resolution_token_map)RemindersReadAPI)RemindersWriteAPI)CloudKitRemindersClient)AlarmAlarmWithTriggerHashtagImageAttachmentListRemindersResultLocationTrigger	ProximityRecurrenceFrequencyRecurrenceRuleReminderReminderChangeEventRemindersListURLAttachmentc                      e Zd ZdZdZdZdZddd fdZddZ	 dddZ	ddZ
ddddZddZ	 	 	 	 	 	 	 	 ddd.Zdd1Zdd2Zddd3d3d4ej        fdd=Zdd@ZddBZddCZ	 dddHZdddddddIddQZddRZej        dSd!d!dTdd[ZdddddTdd^Zdd_Z	 	 ddddZddfZddhZ ddjZ!ddlZ"ddoZ#ddqZ$ddtZ%ddxZ&ddyZ'dd{Z(dd}Z)ddZ*ddZ+ddZ, xZ-S )RemindersServicez
    Typed Reminders API for snapshot reads, incremental sync, and mutations.

    Use this service for list discovery, reminder CRUD, and supported reminder
    metadata such as alarms, hashtags, attachments, and recurrence rules.
    zcom.apple.reminders
productionprivateN)cloudkit_validation_extraservice_rootstrsessionr   paramsDict[str, Any]r'   CloudKitExtraMode | Nonec                   t                                          |||            j         d j         d j         d j         }ddd|pi }t          ||||           _        d	 fd}t          |t                     _
        t          | j
        t                     _        t          | j
        t                     _        d S )
Nz/database/1//T)
remapEnumsgetCurrentSyncToken)validation_extrareturnr   c                      j         S N)_rawselfs   k/home/thesage/.hermes/hermes-agent/venv/lib/python3.11/site-packages/pyicloud/services/reminders/service.pyget_rawz*RemindersService.__init__.<locals>.get_rawi   s    9    )r3   r   )super__init__r(   
_CONTAINER_ENV_SCOPEr   r6   r   LOGGER_mapperr   _readsr   _writes)	r8   r(   r*   r+   r'   endpointbase_paramsr:   	__class__s	   `       r9   r=   zRemindersService.__init__P   s	    	w777  ; ;; ;!%; ;-1[; ; 	
 #'
 
 |

 ,6	
 
 
		 	 	 	 	 	 -Wf==&wfEE($,GGr;   r3   Iterable[RemindersList]c                4    | j                                         S )z
        Yield reminder lists as ``RemindersList`` models.

        Use this to discover available lists and obtain the ``list_id`` values
        needed by creation and query helpers.
        )rC   listsr7   s    r9   rJ   zRemindersService.listsp   s     {  """r;   list_idOptional[str]Iterable[Reminder]c              #     K   i }|r|g}nd |                                  D             }|D ].}|                     |dd          }|j        D ]}|||j        <   /|                                D ]}|V  dS )z
        Yield reminders across all lists or for a specific list.

        Args:
            list_id: Optional list identifier. When provided, only reminders in
                that list are returned.
        c                    g | ]	}|j         
S  )id).0lsts     r9   
<listcomp>z.RemindersService.reminders.<locals>.<listcomp>   s    7773777r;   T   rK   include_completedresults_limitN)rJ   list_reminders	remindersrQ   values)r8   rK   reminder_maplist_idslidbatchreminders          r9   rZ   zRemindersService.remindersy   s       -/  	8yHH77$**,,777H 	5 	5C''"&! (  E
 "O 5 5,4X[))5 %++-- 	 	HNNNN	 	r;   c                4    | j                                         S )z
        Return the current sync token for the Reminders zone.

        Persist this token and pass it to ``iter_changes(since=...)`` later to
        enumerate only newer changes.
        )rC   sync_cursorr7   s    r9   rb   zRemindersService.sync_cursor   s     {&&(((r;   sincerd   Iterable[ReminderChangeEvent]c               8    | j                             |          S )a  
        Yield reminder change events since an optional sync token.

        Updated reminders are returned with ``type="updated"`` and a hydrated
        ``reminder`` payload. Deletions are returned with ``type="deleted"``
        and only the ``reminder_id`` populated.
        rc   )rC   iter_changes)r8   rd   s     r9   rg   zRemindersService.iter_changes   s     {''e'444r;   reminder_idr   c                6    | j                             |          S )z~
        Return a single reminder by ID.

        Args:
            reminder_id: The full reminder record identifier.
        )rC   get)r8   rh   s     r9   rj   zRemindersService.get   s     {{+++r;    Fr   titledesc	completedbooldue_dateOptional[datetime]priorityintflaggedall_day	time_zoneparent_reminder_idc                J    | j                             |||||||||	|

  
        S )a  
        Create a reminder and return the hydrated ``Reminder`` model.

        Args:
            list_id: Target reminder list ID.
            title: Reminder title.
            desc: Reminder notes/body text.
            completed: Whether the reminder should be created as completed.
            due_date: Optional due date. Naive datetimes are treated as UTC.
            priority: Apple Reminders priority value. Common values are
                ``0`` (none), ``1`` (high), ``5`` (medium), and ``9`` (low).
            flagged: Whether the reminder is flagged.
            all_day: Whether the reminder should be treated as all-day.
            time_zone: Optional time zone name for the due date.
            parent_reminder_id: Optional parent reminder ID for subtasks.
        )
rK   rl   rm   rn   rp   rr   rt   ru   rv   rw   )rD   create)r8   rK   rl   rm   rn   rp   rr   rt   ru   rv   rw   s              r9   ry   zRemindersService.create   sA    : |""1 # 
 
 	
r;   r`   Nonec                :    | j                             |           dS )z
        Persist changes made to a ``Reminder`` model back to iCloud.

        Fetch the reminder, mutate its fields locally, then pass it to
        ``update()``.
        N)rD   updater8   r`   s     r9   r|   zRemindersService.update         	H%%%%%r;   c                :    | j                             |           dS )z
        Soft-delete a reminder in iCloud.

        The provided ``Reminder`` model is marked deleted and the remote record
        is updated accordingly.
        N)rD   deleter}   s     r9   r   zRemindersService.delete   r~   r;   g        g      Y@addresslatitudefloat	longituderadius	proximityr   tuple[Alarm, LocationTrigger]c           	     D    | j                             |||||||          S )z
        Add a location-based alarm trigger to a reminder.

        Returns the created ``Alarm`` and ``LocationTrigger`` records.
        )r`   rl   r   r   r   r   r   )rD   add_location_trigger)r8   r`   rl   r   r   r   r   r   s           r9   r   z%RemindersService.add_location_trigger   s8     |00 1 
 
 	
r;   namer   c                8    | j                             ||          S )z,Create and attach a hashtag to ``reminder``.)rD   create_hashtag)r8   r`   r   s      r9   r   zRemindersService.create_hashtag  s    |**8T:::r;   hashtagc                <    | j                             ||           dS )z
        Update a hashtag name.

        Note: the iCloud Reminders web app currently treats hashtag names as
        effectively read-only in some live flows, so rename behavior may not be
        reflected consistently outside the API.
        N)rD   update_hashtag)r8   r   r   s      r9   r   zRemindersService.update_hashtag  s"     	##GT22222r;   c                <    | j                             ||           dS )z.Detach and delete a hashtag from ``reminder``.N)rD   delete_hashtag)r8   r`   r   s      r9   r   zRemindersService.delete_hashtag  s     ##Hg66666r;   
public.urlurlutir"   c                :    | j                             |||          S )z(Create a URL attachment on ``reminder``.)rD   create_url_attachment)r8   r`   r   r   s       r9   r   z&RemindersService.create_url_attachment  s     |11(CEEEr;   r   r   filename	file_sizewidthheight
attachment
Attachmentr   r   Optional[int]r   r   c          	     H    | j                             |||||||           dS )z
        Update a reminder attachment in place.

        URL attachments can update ``url`` and ``uti``. Image attachments can
        update metadata such as filename, size, and dimensions.
        r   N)rD   update_attachment)r8   r   r   r   r   r   r   r   s           r9   r   z"RemindersService.update_attachment(  sB    " 	&& 	' 	
 	
 	
 	
 	
r;   c                <    | j                             ||           dS )z2Detach and delete an attachment from ``reminder``.N)rD   delete_attachment)r8   r`   r   s      r9   r   z"RemindersService.delete_attachmentC  s     &&x<<<<<r;   r   	frequencyintervaloccurrence_countfirst_day_of_weekr   r   r   r   r   r   c               @    | j                             |||||          S )z
        Create and attach a recurrence rule to ``reminder``.

        ``occurrence_count=0`` means the recurrence is open-ended.
        r   )rD   create_recurrence_rule)r8   r`   r   r   r   r   s         r9   r   z'RemindersService.create_recurrence_ruleG  s2     |22-/ 3 
 
 	
r;   recurrence_ruleOptional[RecurrenceFrequency]c               D    | j                             |||||           dS )z-Update fields on an existing recurrence rule.r   N)rD   update_recurrence_rule)r8   r   r   r   r   r   s         r9   r   z'RemindersService.update_recurrence_rule]  s<     	++-/ 	, 	
 	
 	
 	
 	
r;   c                <    | j                             ||           dS )z6Detach and delete a recurrence rule from ``reminder``.N)rD   delete_recurrence_rule)r8   r`   r   s      r9   r   z'RemindersService.delete_recurrence_ruleo  s"     	++HoFFFFFr;   rU   rW   rX   r   c                <    | j                             |||          S )z
        Return a compound reminder snapshot for one list.

        The result includes the list's reminders plus related alarms,
        triggers, attachments, hashtags, and recurrence rules keyed by ID.
        rV   )rC   rY   )r8   rK   rW   rX   s       r9   rY   zRemindersService.list_remindersw  s,     {))/' * 
 
 	
r;   List[AlarmWithTrigger]c                6    | j                             |          S )zJReturn alarm rows, including attached location triggers, for ``reminder``.)rC   
alarms_forr}   s     r9   r   zRemindersService.alarms_for  s    {%%h///r;   List[Hashtag]c                6    | j                             |          S )z3Return hashtags currently attached to ``reminder``.)rC   tags_forr}   s     r9   r   zRemindersService.tags_for  s    {##H---r;   List[Attachment]c                6    | j                             |          S )z6Return attachments currently attached to ``reminder``.)rC   attachments_forr}   s     r9   r   z RemindersService.attachments_for  s    {**8444r;   List[RecurrenceRule]c                6    | j                             |          S )z;Return recurrence rules currently attached to ``reminder``.)rC   recurrence_rules_forr}   s     r9   r   z%RemindersService.recurrence_rules_for  s    {//999r;   encrypted_valuestr | bytesc                     t          |          S r5   )r   )r8   r   s     r9   r   z&RemindersService._decode_crdt_document  s    $_555r;   textc                     t          |          S r5   )r   )r8   r   s     r9   r   z&RemindersService._encode_crdt_document  s    $T***r;   fields_modified	list[str]c                     t          |          S r5   )r   )r8   r   s     r9   r   z/RemindersService._generate_resolution_token_map  s    -o>>>r;   recr   r!   c                6    | j                             |          S r5   )rB   record_to_listr8   r   s     r9   _record_to_listz RemindersService._record_to_list  s    |**3///r;   c                6    | j                             |          S r5   )rB   record_to_reminderr   s     r9   _record_to_reminderz$RemindersService._record_to_reminder  s    |..s333r;   r   c                6    | j                             |          S r5   )rB   record_to_alarmr   s     r9   _record_to_alarmz!RemindersService._record_to_alarm  s    |++C000r;   Optional[LocationTrigger]c                6    | j                             |          S r5   )rB   record_to_alarm_triggerr   s     r9   _record_to_alarm_triggerz)RemindersService._record_to_alarm_trigger  s    |33C888r;   Optional[Attachment]c                6    | j                             |          S r5   )rB   record_to_attachmentr   s     r9   _record_to_attachmentz&RemindersService._record_to_attachment  s    |00555r;   c                6    | j                             |          S r5   )rB   record_to_hashtagr   s     r9   _record_to_hashtagz#RemindersService._record_to_hashtag  s    |--c222r;   c                6    | j                             |          S r5   )rB   record_to_recurrence_ruler   s     r9   _record_to_recurrence_rulez+RemindersService._record_to_recurrence_rule  s    |55c:::r;   )r(   r)   r*   r   r+   r,   r'   r-   )r3   rH   r5   )rK   rL   r3   rM   )r3   r)   )rd   rL   r3   re   )rh   r)   r3   r   )rk   FNr   FFNN)rK   r)   rl   r)   rm   r)   rn   ro   rp   rq   rr   rs   rt   ro   ru   ro   rv   rL   rw   rL   r3   r   )r`   r   r3   rz   )r`   r   rl   r)   r   r)   r   r   r   r   r   r   r   r   r3   r   )r`   r   r   r)   r3   r   )r   r   r   r)   r3   rz   )r`   r   r   r   r3   rz   )r   )r`   r   r   r)   r   r)   r3   r"   )r   r   r   rL   r   rL   r   rL   r   r   r   r   r   r   r3   rz   )r`   r   r   r   r3   rz   )r`   r   r   r   r   rs   r   rs   r   rs   r3   r   )r   r   r   r   r   r   r   r   r   r   r3   rz   )r`   r   r   r   r3   rz   )FrU   )rK   r)   rW   ro   rX   rs   r3   r   )r`   r   r3   r   )r`   r   r3   r   )r`   r   r3   r   )r`   r   r3   r   )r   r   r3   r)   )r   r)   r3   r)   )r   r   r3   r)   )r   r   r3   r!   )r   r   r3   r   )r   r   r3   r   )r   r   r3   r   )r   r   r3   r   )r   r   r3   r   )r   r   r3   r   ).__name__
__module____qualname____doc__r>   r?   r@   r=   rJ   rZ   rb   rg   rj   ry   r|   r   r   ARRIVINGr   r   r   r   r   r   r   r   DAILYr   r   r   rY   r   r   r   r   r   r   r   r   r   r   r   r   r   r   __classcell__)rG   s   @r9   r$   r$   D   s         'JDF ?CH H H H H H H H@# # # # "&    >) ) ) )  $5 5 5 5 5 5, , , , '+#',0(
 (
 (
 (
 (
T& & & && & & & (1
 
 
 
 
2; ; ; ;3 3 3 37 7 7 7  	F F F F F "!"&#'# $
 
 
 
 
 
6= = = = *=)B !!"
 
 
 
 
 
4 48"&*.+/
 
 
 
 
 
$G G G G #( 	
 
 
 
 
$0 0 0 0. . . .5 5 5 5: : : :
6 6 6 6+ + + +? ? ? ?0 0 0 04 4 4 41 1 1 19 9 9 96 6 6 63 3 3 3; ; ; ; ; ; ; ;r;   r$   )1r   
__future__r   loggingr   typingr   r   r   r   r	   r
   pyicloud.common.cloudkitr   pyicloud.common.cloudkit.baser   pyicloud.services.baser   _mappersr   	_protocolr   r   r   rC   r   rD   r   clientr   modelsr   r   r   r   r   r   r   r   r   r   r    r!   r"   	getLoggerr   rA   r   r$   rP   r;   r9   <module>r      s   6 # " " " " "        = = = = = = = = = = = = = = = = - - - - - - ; ; ; ; ; ; . . . . . . + + + + + +         
 % $ $ $ $ $ & & & & & & + + + + + +                               
	8	$	$=/12
r; r; r; r; r;{ r; r; r; r; r;r;   