o
    .j(                     @  sv   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r0ddlmZ ddlmZ eG d	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                   @  s   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	dZ
ded< dZded< d	Zd
ed< edddddZded< edddddZd
ed< ed.ddZd/ddZdd Zd0d!d"Zd1d2d$d%Zd3d'd(Zd4d*d+Zd4d,d-ZdS )5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                 C  sL   | |d |d | d| d| dd| di | d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    r&   Q/home/thesage/.local/lib/python3.10/site-packages/caldav/jmap/objects/calendar.py	from_jmap3   s   



zJMAPCalendar.from_jmapc                 C  sB   | j | j| j| jd}| jdur| j|d< | jdur| 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dr&   r&   r'   to_jmapE   s   



zJMAPCalendar.to_jmapc                 K  sl   | j r| jdi |S |d}|d}t|tr| }t|tr'| }| jj| j|||d| 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_idr,   r-   r.   parentNr&   )	r   _async_searchr$   
isinstancer   	isoformatr   _searchr   r)   
searchargsr,   r-   r&   r&   r'   searchX   s   



zJMAPCalendar.searchlist[JMAPCalendarObject]c                   s^   | d}| d}t|tr| }t|tr| }| jj| j||| d| dI d H S )Nr,   r-   r.   r/   )r$   r3   r   r4   r   r5   r   r6   r&   r&   r'   r2   }   s   



zJMAPCalendar._async_searchuidc                 C  s$   | j r| |S | jj|| j| d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.
        r0   r1   )r   _async_get_object_by_uidr   _get_object_by_uidr   )r)   r:   
comp_classr&   r&   r'   get_object_by_uid   s   
zJMAPCalendar.get_object_by_uidr   c                   s   | j j|| j| dI d H S )Nr;   )r   r=   r   )r)   r:   r&   r&   r'   r<      s   z%JMAPCalendar._async_get_object_by_uidical_strc                 C  s    | 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)   r@   r&   r&   r'   	add_event   s   
zJMAPCalendar.add_eventc                   s   | j | j|I d H S N)r   rB   r   rC   r&   r&   r'   rA      s   zJMAPCalendar._async_add_event)r   r   r   r
   )r   r   )r   r9   rE   )r:   r   )r:   r   r   r   )r@   r   r   r   )__name__
__module____qualname____doc____annotations__r   r   r   r   r   r   r   r   r   r   classmethodr(   r+   r8   r2   r?   r<   rD   rA   r&   r&   r&   r'   r
      s.   
 

%

r
   N)rI   
__future__r   dataclassesr   r   r   typingr   #caldav.jmap.objects.calendar_objectr   caldav.jmap.async_clientr   caldav.jmap.clientr	   r
   r&   r&   r&   r'   <module>   s    