
    3fi                         d Z ddlZddlmZ ddl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  G d	 d
e      Z G d de      Zy)z#Search an event in Google Calendar.    N)datetime)AnyDictListOptionalType)ZoneInfo)CallbackManagerForToolRun)	BaseModelField)CalendarBaseToolc                       e Zd ZU dZ edd      Zeed<    edd      Zeed<    edd      Z	eed	<    ed
d      Z
eed<    edd      Zeed<    edd      Zeed<    edd      Zee   ed<   y)SearchEventsSchemaz(Input schema for `CalendarSearchEvents`..znA list with the information about all Calendars in Google CalendarUse the tool 'get_calendars_info' to get it.)descriptioncalendars_infozThe start datetime for the events in 'YYYY-MM-DD HH:MM:SS' format. If you do not know the current datetime, use the tool to get it.min_datetimez'The end datetime for the events search.max_datetime
   z(The maximum number of results to return.)defaultr   max_resultsTzWhether to expand recurring events into instances and only return single one-off events and instances of recurring events.'startTime' or 'updated'.single_events	startTimez9The order of the events, either 'startTime' or 'updated'.order_byNzFree text search terms to find events, that match these terms in the following fields: summary, description, location, attendee's displayName, attendee's email, organizer's displayName, organizer's email.query)__name__
__module____qualname____doc__r   r   str__annotations__r   r   r   intr   boolr   r   r        o/var/www/auto_recruiter/arenv/lib/python3.12/site-packages/langchain_google_community/calendar/search_events.pyr   r      s    2;NC  OL#  BL#   JK   (M4  OHc 
 !:E8C= r$   r   c                   "   e Zd ZU dZdZeed<   dZeed<   eZ	e
e   ed<   deeeef      ded	ee   fd
Zdeeeef      d	ee   fdZdeeeef      d	eeeee   f      fdZ	 	 	 	 	 ddededededededee   dee   d	eeeee   f      fdZy)CalendarSearchEventsz0Tool that retrieves events from Google Calendar.search_eventsnamez/Use this tool to search events in the calendar.r   args_schemar   calendar_idreturnc                 H    |D ]  }|d   |k(  s|j                  d      c S  y)z)Get the timezone of the current calendar.idtimeZoneN)get)selfr   r+   cals       r%   _get_calendar_timezonez+CalendarSearchEvents._get_calendar_timezoneK   s3     " 	+C4yK'wwz**	+ r$   c                 2    |D cg c]  }|d   	 c}S c c}w )zGet the calendar IDs.r.   r#   )r1   r   r2   s      r%   _get_calendar_idsz&CalendarSearchEvents._get_calendar_idsT   s    %34cD	444s   events_datac                 0   g }|D ]  }|j                  d      |j                  d      |j                  d      |j                  di       j                  d      |j                  di       j                  d      |j                  di       j                  d      xs! |j                  di       j                  d	      |j                  d
i       j                  d      xs! |j                  d
i       j                  d	      d}|j                  |        |S )zProcess the data events.r.   htmlLinksummarycreatoremail	organizerstartdateTimedateend)r.   r8   r9   r:   r<   r=   r@   )r0   append)r1   r6   simplified_datadata
event_dicts        r%   _process_data_eventsz)CalendarSearchEvents._process_data_eventsX   s      	/Dhhtn HHZ088I.88Ir266w?!XXk26::7C'2.22:> 588GR(,,V4xxr*..z: 388E2&**62
J "":.	/ r$   Nr   r   r   r   r   r   run_managerc	           
         	 t        j                  |      }	| j                  |	      }
g }|
D ]  }| j                  |	|      }|rt	        |      nd}t        j                  |d      j                  |      j                         }t        j                  |d      j                  |      j                         }| j                  j                         j                  |||||||      j                         }|j                  dg       }|j                  |        | j                  |      S # t         $ r}t!        d|       |d}~ww xY w)z1Run the tool to search events in Google Calendar.Nz%Y-%m-%d %H:%M:%S)tzinfo)
calendarIdtimeMintimeMax
maxResultssingleEventsorderByqitemsz)An error occurred while fetching events: )jsonloadsr5   r3   r	   r   strptimereplace	isoformatapi_resourceeventslistexecuter0   extendrE   	Exception)r1   r   r   r   r   r   r   r   rF   calendars_data	calendarsrW   calendartz_namecalendar_tztime_mintime_maxevents_result
cal_eventserrors                       r%   _runzCalendarSearchEvents._runl   sP   $	!ZZ7N..~>IF% *55nhO3:hw/%%l4GHWKW0Y[  %%l4GHWKW0Y[  %%,,.T#+ ( (#.%2 (   WY  +..w;
j)7*8 ,,V44 	;E7C	s   D)D, ,	E	5EE	)r   Tr   NN)r   r   r   r   r)   r   r    r   r   r*   r   r   r   r   r3   r5   r   rE   r!   r"   r
   rf   r#   r$   r%   r'   r'   B   s;   :D#HKH,>K()>"4S>2AD	#5T#s(^0D 5c 5S#X/	d3%&	'2 "##;?00 0 	0
 0 0 0 }0 780 
d3%&	'0r$   r'   )r   rQ   r   typingr   r   r   r   r   zoneinfor	   langchain_core.callbacksr
   pydanticr   r   (langchain_google_community.calendar.baser   r   r'   r#   r$   r%   <module>rl      s<    )   2 2  > % E1 1hZ+ Zr$   