o
    ÌÄ.jŸ#  ã                   @  sª   d Z ddlmZ ddlmZ 		d7d8dd„Zd9dd„Z	d:d;dd„Zd<dd„Z				d=d>d"d#„Z	d?d%d&„Z
			d@dAd(d)„ZdBd,d-„ZdCd/d0„ZdDd2d3„ZdEd5d6„ZdS )Fu©  
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                 C  ó$   | |dœ}|dur||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	   Úargsr   r   úO/home/thesage/.local/lib/python3.10/site-packages/caldav/jmap/_methods/event.pyÚbuild_event_get   s   

r   Úresponse_argsÚdictú
list[dict]c                 C  s   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   r   r   r   Úparse_event_get(   s   r   Úsince_stateÚmax_changesú
int | Nonec                 C  r   )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   r   r   r   Úbuild_event_changes6   s   

r   ú6tuple[str, str, bool, list[str], list[str], list[str]]c                 C  sF   |   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   r   r   r   Úparse_event_changesM   s   


úr'   Úfilter_conditionúdict | NoneÚsortúlist[dict] | NoneÚpositionÚintÚlimitc                 C  sD   | |dœ}|dur||d< |dur||d< |dur||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   r,   NÚfilterr*   r.   zCalendarEvent/queryz
ev-query-0r   )r   r(   r*   r,   r.   r   r   r   r   Úbuild_event_queryj   s   

r0   útuple[list[str], str, int]c                 C  s2   |   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_stater3   r   r   r   Úparse_event_query‹   s   
r6   Úsince_query_statec                 C  sD   | |dœ}|dur||d< |dur||d< |dur||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   ÚsinceQueryStateNr/   r*   r   zCalendarEvent/queryChangeszev-qchanges-0r   )r   r7   r(   r*   r   r   r   r   r   Úbuild_event_query_changes¡   s   

r9   Úeventsúdict[str, dict]c                 C  s   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   r:   r   r   r   Úbuild_event_set_create¿   s   þúr>   Úupdatesc                 C  ó   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)``.
    r<   )r   Úupdatezev-set-update-0r   )r   r?   r   r   r   Úbuild_event_set_updateÙ   s   ýrB   ú	list[str]c                 C  r@   )z÷Build 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)``.
    r<   )r   Údestroyzev-set-destroy-0r   )r   r   r   r   r   Úbuild_event_set_destroyð   s   ýrE   ú.tuple[dict, dict, list[str], dict, dict, dict]c                 C  s   t | ƒS )zûParse 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   r   r   r   Úparse_event_set  s   rG   )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*   r+   r,   r-   r.   r   r
   r   )r   r   r
   r1   )NNN)r   r   r7   r   r(   r)   r*   r+   r   r   r
   r   )r   r   r:   r;   r
   r   )r   r   r?   r;   r
   r   )r   r   r   rC   r
   r   )r   r   r
   rF   )Ú__doc__Ú
__future__r   Úcaldav.jmap._methodsr   r   r   r   r'   r0   r6   r9   r>   rB   rE   rG   r   r   r   r   Ú<module>   s0    ý
ý
û
!û


