o
    Zh#                     @   s   d 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mZ ddlmZ dd	lmZ G d
d deZG dd deZdS )z#Create an event in Google Calendar.    N)datetime)AnyDictListOptionalTypeUnion)uuid4)CallbackManagerForToolRun)	BaseModelField)CalendarBaseTool)is_all_day_eventc                   @   sT  e Zd ZU dZedddZeed< edddZeed< edddZ	eed	< edd
dZ
eed< edddZeed< edddZeeeef  ed< edddZee ed< edddZee ed< edddZeee  ed< edddZedeeeeef  f ed< edddZee ed< edddZee ed< edddZee ed < dS )!CreateEventSchemazInput for CalendarCreateEvent..zThe title of the event.)descriptionsummaryzThe start datetime for the event in 'YYYY-MM-DD HH:MM:SS' format.If the event is an all-day event, set the time to 'YYYY-MM-DD' format.If you do not know the current datetime, use the tool to get it.start_datetimezThe end datetime for the event in 'YYYY-MM-DD HH:MM:SS' format. If the event is an all-day event, set the time to 'YYYY-MM-DD' format.end_datetimezThe timezone of the event.timezoneprimaryz'The calendar ID to create the event in.)defaultr   calendar_idNa  The recurrence of the event. Format: {'FREQ': <'DAILY' or 'WEEKLY'>, 'INTERVAL': <number>, 'COUNT': <number or None>, 'UNTIL': <'YYYYMMDD' or None>, 'BYDAY': <'MO', 'TU', 'WE', 'TH', 'FR', 'SA', 'SU' or None>}. Use either COUNT or UNTIL, but not both; set the other to None.
recurrencezThe location of the event.locationzThe description of the event.r   z3A list of attendees' email addresses for the event.	attendeeszReminders for the event. Set to True for default reminders, or provide a list like [{'method': 'email', 'minutes': <minutes>}, ...]. Valid methods are 'email' and 'popup'.	remindersz#Whether to include conference data.conference_datazThe color ID of the event. None for default. '1': Lavender, '2': Sage, '3': Grape, '4': Flamingo, '5': Banana, '6': Tangerine, '7': Peacock, '8': Graphite, '9': Blueberry, '10': Basil, '11': Tomato.color_idzNUser availability for the event.transparent for available and opaque for busy.transparency)__name__
__module____qualname____doc__r   r   str__annotations__r   r   r   r   r   r   r   r   r   r   r   r   r   r   boolr   r   r    r&   r&   g/var/www/html/lang_env/lib/python3.10/site-packages/langchain_google_community/calendar/create_event.pyr      sV   
 
$		r   c                   @   sn  e Zd ZU dZdZeed< dZeed< eZ	e
e ed< 								dded	ed
ededeeeef  dee dee deee  dedeeeeef  f dee dee dee deeef fddZ										dded	ed
edededeeeef  dee dee deee  dedeeeeef  f dee dee dee dee defddZdS )CalendarCreateEventz.Tool that creates an event in Google Calendar.Zcreate_calendar_eventnamezlUse this tool to create an event. The input must include the summary, start, and end datetime for the event.r   args_schemaNr   r   r   r   r   r   r   r   r   r   r   returnc              
   C   s  z0t ||rd|i}d|i}n d}t||}t||}|  |d}|  |d}W n tyA } ztd|d}~ww d}|r[t|tr[dd | D }dd		| }g }|rzd
}|D ]}t
||srtd| |d|i qci }|	du r|ddi n0t|	tr|	D ]}d|vsd|vrtd|d dvrtdq|d|	d n|ddi d}|
rdtt ddidi}|||d}|r||d< |r||d< |r|g|d< t|dkr||d< t|dkr||d < |r||d!< |r||d"< |r	||d#< |S )$zPrepare the event body.datez%Y-%m-%d %H:%M:%S)ZdateTimeZtimeZonez!The datetime format is incorrect.Nc                 S   s&   g | ]\}}|d ur| d| qS )N=r&   ).0kvr&   r&   r'   
<listcomp>   s     z6CalendarCreateEvent._prepare_event.<locals>.<listcomp>zRRULE:;z^[^@]+@[^@]+\.[^@]+$zInvalid email address: emailT
useDefaultmethodminutesz4Each reminder must have 'method' and 'minutes' keys.)r3   Zpopupz-The reminder method must be 'email' or 'popupF)r4   Z	overridesZcreateRequesttypeZhangoutsMeet)Z	requestIdZconferenceSolutionKey)r   startendr   r   r   r   r   r   ZconferenceDataZcolorIdr   )r   r   strptime
astimezone	isoformat
ValueError
isinstancedictitemsjoinrematchappendupdatelistr#   r	   len)selfr   r   r   r   r   r   r   r   r   r   r   r   r8   r9   Zdatetime_formatZstart_dtZend_dterrorZrecurrence_dataZrecurrence_itemsZattendees_emailsZemail_patternr3   Zreminders_infoZreminderZconference_data_infoZ
event_bodyr&   r&   r'   _prepare_eventa   s   







z"CalendarCreateEvent._prepare_eventr   r   run_managerc                 C   s   z-| j ||||||||	|
|||d}|rdnd}| j j|||d }d|d W S  tyA } ztd| |d}~ww )	z3Run the tool to create an event in Google Calendar.)r   r   r   r   r   r   r   r   r   r   r   r      r   )Z
calendarIdbodyZconferenceDataVersionzEvent created: ZhtmlLinkzAn error occurred: N)rJ   Zapi_resourceeventsinsertexecuteget	Exception)rH   r   r   r   r   r   r   r   r   r   r   r   r   r   rK   rM   Zconference_versioneventrI   r&   r&   r'   _run   s:   	zCalendarCreateEvent._run)NNNNNNNN)
r   NNNNNNNNN)r   r    r!   r"   r)   r#   r$   r   r   r*   r   r   r   r   r   r   r%   rJ   r
   rT   r&   r&   r&   r'   r(   W   s   
 

	


_	

r(   )r"   rB   r   typingr   r   r   r   r   r   uuidr	   Zlangchain_core.callbacksr
   Zpydanticr   r   Z(langchain_google_community.calendar.baser   Z)langchain_google_community.calendar.utilsr   r   r(   r&   r&   r&   r'   <module>   s     H