
    i(                        d Z ddlmZ ddlmZmZ ddlmZ ddlmZ ddl	m
Z
 erddlmZ ddlmZ e G d	 d
                      ZdS )z
JMAP Calendar object.

Represents a JMAP Calendar resource as returned by ``Calendar/get``.
Properties are defined in the JMAP Calendars specification.
    )annotations)	dataclassfield)datetime)TYPE_CHECKING)JMAPCalendarObject)AsyncJMAPClient)
JMAPClientc                  0   e Zd ZU dZded<   ded<   dZded<   dZded<   d	Zd
ed<    ee	          Z
ded<   dZded<   d	Zd
ed<    edddd          Zded<    edddd          Zd
ed<   ed&d            Zd'dZd Zd(dZd)d*d Zd+d"Zd,d$Zd,d%ZdS )-JMAPCalendaru  A JMAP Calendar object.

    Attributes:
        id: Server-assigned calendar identifier.
        name: Display name of the calendar.
        description: Optional longer description.
        color: Optional CSS color string (e.g. ``"#ff0000"``).
        is_subscribed: Whether the user is subscribed to this calendar.
        my_rights: Dict of right names → bool for the current user.
        sort_order: Hint for display ordering (lower = first).
        is_visible: Whether the calendar should be displayed.
    stridnameNz
str | NonedescriptioncolorTboolis_subscribed)default_factorydict	my_rightsr   int
sort_order
is_visibleF)defaultinitreprcomparez#JMAPClient | AsyncJMAPClient | None_client	_is_asyncdatareturnc                ,    | |d         |d         |                     d          |                     d          |                     dd          |                     di           |                     dd	          |                     d
d                    S )zConstruct a JMAPCalendar from a raw JMAP Calendar JSON dict.

        Unknown keys in ``data`` are silently ignored so that forward
        compatibility is maintained as the spec evolves.
        r   r   r   r   isSubscribedTmyRights	sortOrderr   	isVisible)r   r   r   r   r   r   r   r   )get)clsr    s     W/root/projects/butler/venv/lib/python3.11/site-packages/caldav/jmap/objects/calendar.py	from_jmapzJMAPCalendar.from_jmap3   s     sDzf//((7##((>488hhz2..xxQ//xxT22	
 	
 	
 		
    c                    | j         | j        | j        | j        d}| j        
| j        |d<   | j        
| j        |d<   |S )u!  Serialise to a JMAP Calendar JSON dict for ``Calendar/set``.

        ``id`` and ``myRights`` are intentionally excluded — both are
        server-set and must not appear in create or update payloads.
        Optional fields are included only when they hold a non-default value.
        )r   r#   r%   r&   Nr   r   )r   r   r   r   r   r   )selfds     r)   to_jmapzJMAPCalendar.to_jmapE   sU     I .	
 
 '#/Am:!AgJr+   c                   | j         r | j        di |S |                    d          }|                    d          }t          |t                    r|                                }t          |t                    r|                                }| j                            | j        |||                    d          |           S )a5  Search for calendar objects in this calendar.

        Mirrors :meth:`caldav.collection.Calendar.search`. When called on an
        async-backed calendar, returns a coroutine that must be awaited.

        Accepted keyword arguments (all optional):

        - ``start`` (datetime or str): only events ending after this time
          (maps to JMAP ``after`` filter).
        - ``end`` (datetime or str): only events starting before this time
          (maps to JMAP ``before`` filter).
        - ``text`` (str): free-text search across title, description,
          locations, and participants.

        Unknown parameters are silently ignored for backward compatibility.

        Returns:
            List of :class:`~caldav.jmap.objects.calendar_object.JMAPCalendarObject`
            for all matching objects.
        startendtextcalendar_idr1   r2   r3   parent )	r   _async_searchr'   
isinstancer   	isoformatr   _searchr   r-   
searchargsr1   r2   s       r)   searchzJMAPCalendar.searchX   s    * > 	4%4%33
333w''nnU##eX&& 	&OO%%Ec8$$ 	"--//C|##'' $ 
 
 	
r+   list[JMAPCalendarObject]c                x  K   |                     d          }|                     d          }t          |t                    r|                                }t          |t                    r|                                }| j                            | j        |||                     d          |            d {V S )Nr1   r2   r3   r4   )r'   r9   r   r:   r   r;   r   r<   s       r)   r8   zJMAPCalendar._async_search}   s      w''nnU##eX&& 	&OO%%Ec8$$ 	"--//C\))'' * 
 
 
 
 
 
 
 
 	
r+   uidc                ~    | j         r|                     |          S | j                            || j        |           S )a  Get a calendar object by its iCalendar UID.

        Mirrors :meth:`caldav.collection.Calendar.get_object_by_uid`. When
        called on an async-backed calendar, returns a coroutine that must be
        awaited.

        Args:
            uid: The iCalendar UID to search for.
            comp_class: Accepted for API compatibility with the CalDAV interface;
                JMAP ``CalendarEvent/query`` has no native component-type filter,
                so this argument is currently ignored.

        Returns:
            A :class:`~caldav.jmap.objects.calendar_object.JMAPCalendarObject`
            for the matching object.

        Raises:
            JMAPMethodError: If no object with this UID is found.
        r5   r6   )r   _async_get_object_by_uidr   _get_object_by_uidr   )r-   rA   
comp_classs      r)   get_object_by_uidzJMAPCalendar.get_object_by_uid   sB    ( > 	600555|..sPT.UUUr+   r   c                V   K   | j                             || j        |            d {V S )NrC   )r   rE   r   )r-   rA   s     r)   rD   z%JMAPCalendar._async_get_object_by_uid   s8      \44SdgVZ4[[[[[[[[[r+   ical_strc                z    | j         r|                     |          S | j                            | j        |          S )u  Add an event to this calendar from an iCalendar string.

        Mirrors :meth:`caldav.collection.Calendar.add_event`. When called on
        an async-backed calendar, returns a coroutine that must be awaited.

        Args:
            ical_str: A VCALENDAR string representing the event.

        Returns:
            The server-assigned JMAP event ID. Unlike the CalDAV equivalent,
            this returns a string ID rather than a calendar object — the
            ``CalendarEvent/set`` response does not include the full object,
            so a follow-up GET would be required.

        Raises:
            JMAPMethodError: If the server rejects the create request.
        )r   _async_add_eventr   create_eventr   r-   rI   s     r)   	add_eventzJMAPCalendar.add_event   s<    $ > 	3((222|(((;;;r+   c                R   K   | j                             | j        |           d {V S N)r   rL   r   rM   s     r)   rK   zJMAPCalendar._async_add_event   s2      \..twAAAAAAAAAr+   )r    r   r!   r   )r!   r   )r!   r?   rP   )rA   r   )rA   r   r!   r   )rI   r   r!   r   )__name__
__module____qualname____doc____annotations__r   r   r   r   r   r   r   r   r   r   classmethodr*   r/   r>   r8   rG   rD   rN   rK   r7   r+   r)   r   r      s          GGGIII"K""""EMeD111I1111JJ 4955ue4 4 4G     eEE5QQQIQQQQ
 
 
 [
"   &#
 #
 #
J
 
 
 
V V V V V0\ \ \ \< < < <,B B B B B Br+   r   N)rT   
__future__r   dataclassesr   r   r   typingr   #caldav.jmap.objects.calendar_objectr   caldav.jmap.async_clientr	   caldav.jmap.clientr
   r   r7   r+   r)   <module>r]      s     # " " " " " ( ( ( ( ( ( ( (                   B B B B B B .888888------ hB hB hB hB hB hB hB hB hB hBr+   