
    i#                        d Z ddlmZ ddlmZ 	 	 d,d-dZd.dZ	 d/d0dZd1dZ	 	 	 	 d2d3dZ	d4d Z
	 	 	 d5d6d"Zd7d%Zd8d'Zd9d)Zd:d+ZdS );u  
JMAP CalendarEvent method builders and response parsers.

These are pure functions — no HTTP, no state. They build the request
tuples that go into a ``methodCalls`` list, and parse the corresponding
``methodResponses`` entries.

Method shapes follow RFC 8620 §3.3 (get), §3.4 (changes), §3.5 (set),
§3.6 (query), §3.7 (queryChanges); CalendarEvent-specific properties are
defined in the JMAP Calendars specification.
    )annotationsparse_set_responseN
account_idstridslist[str] | None
propertiesreturntuplec                $    | |d}|||d<   d|dfS )a  Build a ``CalendarEvent/get`` method call tuple.

    Args:
        account_id: The JMAP accountId to query.
        ids: List of event IDs to fetch, or ``None`` to fetch all.
        properties: List of property names to return, or ``None`` for all.

    Returns:
        A 3-tuple ``("CalendarEvent/get", arguments_dict, call_id)`` suitable
        for inclusion in a ``methodCalls`` list.
    )	accountIdr   Nr
   zCalendarEvent/getzev-get-0 )r   r   r
   argss       U/root/projects/butler/venv/lib/python3.11/site-packages/caldav/jmap/_methods/event.pybuild_event_getr      s.       *#66D'\z22    response_argsdict
list[dict]c                H    t          |                     dg                     S )ag  Parse the arguments dict from a ``CalendarEvent/get`` method response.

    Args:
        response_args: The second element of a ``methodResponses`` entry
            whose method name is ``"CalendarEvent/get"``.

    Returns:
        List of raw JSCalendar dicts as returned by the server.
        Returns an empty list if ``"list"`` is absent or empty.
    list)r   getr   s    r   parse_event_getr   (   s"     !!&"--...r   since_statemax_changes
int | Nonec                $    | |d}|||d<   d|dfS )a  Build a ``CalendarEvent/changes`` method call tuple.

    Args:
        account_id: The JMAP accountId to query.
        since_state: The ``state`` string from a previous ``CalendarEvent/get``
            or ``CalendarEvent/changes`` response.
        max_changes: Optional upper bound on the number of changes returned.
            The server may return fewer.

    Returns:
        A 3-tuple ``("CalendarEvent/changes", arguments_dict, call_id)``.
    )r   
sinceStateN
maxChangeszCalendarEvent/changeszev-changes-0r   )r   r   r   r   s       r   build_event_changesr"   6   s.    "  *EED(\#T>::r   6tuple[str, str, bool, list[str], list[str], list[str]]c                   |                      dd          |                      dd          |                      dd          |                      d          pg |                      d          pg |                      d          pg fS )	a  Parse the arguments dict from a ``CalendarEvent/changes`` response.

    Args:
        response_args: The second element of a ``methodResponses`` entry
            whose method name is ``"CalendarEvent/changes"``.

    Returns:
        A 6-tuple ``(old_state, new_state, has_more_changes, created, updated, destroyed)``:

        - ``old_state``: Echo of the ``sinceState`` argument.
        - ``new_state``: State string to store as the next sync token.
        - ``has_more_changes``: True if the server capped the response.
        - ``created``: IDs of newly created events.
        - ``updated``: IDs of modified events.
        - ``destroyed``: IDs of deleted events.
    oldState newStatehasMoreChangesFcreatedupdated	destroyed)r   r   s    r   parse_event_changesr,   M   s    ( 	*b))*b))*E22)$$*)$$*+&&," r   filter_conditiondict | Nonesortlist[dict] | Nonepositionintlimitc                @    | |d}|||d<   |||d<   |||d<   d|dfS )a  Build a ``CalendarEvent/query`` method call tuple.

    Args:
        account_id: The JMAP accountId to query.
        filter_condition: A ``FilterCondition`` or ``FilterOperator`` dict, e.g.
            ``{"after": "2024-01-01T00:00:00Z", "before": "2024-12-31T23:59:59Z"}``.
            ``None`` means no filter (return all events).
        sort: List of ``Comparator`` dicts, e.g.
            ``[{"property": "start", "isAscending": True}]``.
            ``None`` means server default ordering.
        position: Zero-based index of the first result to return.
        limit: Maximum number of IDs to return. ``None`` means no limit.

    Returns:
        A 3-tuple ``("CalendarEvent/query", arguments_dict, call_id)``.
    )r   r1   Nfilterr/   r3   zCalendarEvent/queryz
ev-query-0r   )r   r-   r/   r1   r3   r   s         r   build_event_queryr6   j   sK    .  *x@@D#)XVW!466r   tuple[list[str], str, int]c                    |                      dg           }|                      dd          }|                      dt          |                    }|||fS )a&  Parse the arguments dict from a ``CalendarEvent/query`` response.

    Args:
        response_args: The second element of a ``methodResponses`` entry
            whose method name is ``"CalendarEvent/query"``.

    Returns:
        A 3-tuple ``(ids, query_state, total)``:

        - ``ids``: Ordered list of matching event IDs.
        - ``query_state``: Opaque state string for use with
          ``CalendarEvent/queryChanges``.
        - ``total``: Total number of matching events (may exceed ``len(ids)``
          when a limit was applied).
    r   
queryStater&   total)r   len)r   r   query_stater:   s       r   parse_event_queryr=      sV      #&&ub11C$((r::K""7CHH55EU""r   since_query_statec                @    | |d}|||d<   |||d<   |||d<   d|dfS )aS  Build a ``CalendarEvent/queryChanges`` method call tuple.

    Args:
        account_id: The JMAP accountId to query.
        since_query_state: The ``queryState`` string from a previous
            ``CalendarEvent/query`` or ``CalendarEvent/queryChanges`` response.
        filter_condition: Same filter as the original ``CalendarEvent/query`` call.
        sort: Same sort as the original ``CalendarEvent/query`` call.
        max_changes: Optional upper bound on the number of changes returned.

    Returns:
        A 3-tuple ``("CalendarEvent/queryChanges", arguments_dict, call_id)``.
    )r   sinceQueryStateNr5   r/   r!   zCalendarEvent/queryChangeszev-qchanges-0r   )r   r>   r-   r/   r   r   s         r   build_event_query_changesrA      sM    (  *>OPPD#)XV(\($@@r   eventsdict[str, dict]c                ,    d| t          |          ddfS )u  Build a ``CalendarEvent/set`` method call for creating events.

    Args:
        account_id: The JMAP accountId.
        events: Map of client-assigned creation ID → JSCalendar dict.
            The creation IDs are ephemeral — they are used to correlate
            server responses with individual creation requests within the
            same batch call.

    Returns:
        A 3-tuple ``("CalendarEvent/set", arguments_dict, call_id)``.
    CalendarEvent/set)r   createzev-set-create-0)r   )r   rB   s     r   build_event_set_createrG      s,    " 	#6ll	
 	
 	 r   updatesc                    d| |ddfS )u  Build a ``CalendarEvent/set`` method call for updating events.

    Args:
        account_id: The JMAP accountId.
        updates: Map of event ID → partial patch dict.  Keys are property
            names (or JSON Pointer paths for nested properties); values are
            the new values.  Use ``None`` as a value to reset a property to
            its server default.

    Returns:
        A 3-tuple ``("CalendarEvent/set", arguments_dict, call_id)``.
    rE   )r   updatezev-set-update-0r   )r   rH   s     r   build_event_set_updaterK      s    " 	 G44 r   	list[str]c                    d| |ddfS )zBuild a ``CalendarEvent/set`` method call for destroying events.

    Args:
        account_id: The JMAP accountId.
        ids: List of event IDs to destroy.

    Returns:
        A 3-tuple ``("CalendarEvent/set", arguments_dict, call_id)``.
    rE   )r   destroyzev-set-destroy-0r   )r   r   s     r   build_event_set_destroyrO      s     	 S11 r   .tuple[dict, dict, list[str], dict, dict, dict]c                     t          |           S )zParse the arguments dict from a ``CalendarEvent/set`` method response.

    Returns a 6-tuple ``(created, updated, destroyed, not_created, not_updated, not_destroyed)``.
    See :func:`caldav.jmap._methods.parse_set_response` for field semantics.
    r   r   s    r   parse_event_setrR     s     m,,,r   )NN)r   r   r   r	   r
   r	   r   r   )r   r   r   r   )N)r   r   r   r   r   r   r   r   )r   r   r   r#   )NNr   N)r   r   r-   r.   r/   r0   r1   r2   r3   r   r   r   )r   r   r   r7   )NNN)r   r   r>   r   r-   r.   r/   r0   r   r   r   r   )r   r   rB   rC   r   r   )r   r   rH   rC   r   r   )r   r   r   rL   r   r   )r   r   r   rP   )__doc__
__future__r   caldav.jmap._methodsr   r   r   r"   r,   r6   r=   rA   rG   rK   rO   rR   r   r   r   <module>rV      s[  
 
 # " " " " " 3 3 3 3 3 3
 !#'3 3 3 3 3,/ / / /" #; ; ; ; ;.   > %)"7 7 7 7 7B# # # #2 %)""A A A A A<   4   .   (- - - - - -r   