
    3fi$                         d Z ddlmZmZmZmZ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	e
      Z G d
 de      Zy)z*Tool for creating new Google Spreadsheets.    )AnyDictListOptionalType)CallbackManagerForToolRun)	BaseModelField   )SheetsBaseTool)validate_range_namec                       e Zd ZU dZ ed      Zeed<    edd      Ze	e   ed<    ed	d
      Z
e	e   ed<    edd      Ze	e   ed<    edd      Ze	eee         ed<    edd      Ze	e   ed<   y)CreateSpreadsheetSchemaz/Input schema for `SheetsCreateSpreadsheetTool`.z!The title of the new spreadsheet.)descriptiontitleen_USzrThe locale of the spreadsheet in one of the ISO 639-1 language codes (e.g. 'en_US', 'fr_FR'). Defaults to 'en_US'.)defaultr   localeAmerica/New_YorkzThe time zone of the spreadsheet, specified as a time zone ID from the IANA Time Zone Database (e.g. 'America/New_York', 'Europe/London'). Defaults to 'America/New_York'.	time_zone	ON_CHANGEzThe amount of time to wait before volatile functions are recalculated. Options: 'ON_CHANGE', 'MINUTE', 'HOUR'. Defaults to 'ON_CHANGE'.auto_recalcNzOptional initial data to populate the spreadsheet. 2D array where each inner array represents a row. Supports strings, numbers, booleans, and formulas.initial_dataA1z@The range where initial data should be placed. Defaults to 'A1'.initial_range)__name__
__module____qualname____doc__r
   r   str__annotations__r   r   r   r   r   r   r   r        w/var/www/auto_recruiter/arenv/lib/python3.12/site-packages/langchain_google_community/sheets/create_spreadsheet_tool.pyr   r      s    9#FGE3G!KFHSM   %"@ Ix}  "''"K#  /4A/L(4S	?+  $)V$M8C= 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ded	ee   d
ee   dee   deeee         dee   dee   deeef   fdZy)SheetsCreateSpreadsheetToolaH	  Tool for creating new Google Spreadsheets.

    Inherits from
    [`SheetsBaseTool`][langchain_google_community.sheets.base.SheetsBaseTool].

    Creates spreadsheets with configurable properties and optional initial data.

    !!! note "Authentication Required"
        Requires OAuth2 authentication. Use `api_resource` parameter with
        authenticated Google Sheets service.

    Tool Output:
        success (bool): Whether operation succeeded.
        spreadsheet_id (str): Unique ID of the created spreadsheet.
        spreadsheet_url (str): Direct URL to open the spreadsheet.
        title (str): The spreadsheet title.
        locale (str): The locale setting.
        time_zone (str): The timezone setting.
        auto_recalc (str): The recalculation setting.
        created (bool): Whether creation succeeded.
        initial_data_added (bool): Whether initial data was added (if provided).
        initial_data_cells_updated (int): Number of cells updated (if data added).
        initial_data_range (str): Range where data was placed (if data added).

    ???+ example "Basic Usage"

        Create a simple spreadsheet:

        ```python
        from langchain_google_community.sheets import SheetsCreateSpreadsheetTool

        tool = SheetsCreateSpreadsheetTool(api_resource=service)
        result = tool.run({"title": "My New Spreadsheet"})
        print(f"Created: {result['spreadsheet_url']}")
        ```


    ??? example "With Initial Data"

        Create spreadsheet with pre-populated data:

        ```python
        result = tool.run(
            {
                "title": "Sales Report",
                "initial_data": [
                    ["Name", "Region", "Sales"],
                    ["Alice", "East", "95000"],
                    ["Bob", "West", "87000"],
                ],
                "initial_range": "A1",
            }
        )
        ```


    ??? example "Custom Configuration"

        Create with locale and timezone settings:

        ```python
        result = tool.run(
            {
                "title": "European Report",
                "locale": "fr_FR",
                "time_zone": "Europe/Paris",
                "auto_recalc": "HOUR",
            }
        )
        ```

    Raises:
        ValueError: If write permissions unavailable or validation fails.
        Exception: If API call fails.
    sheets_create_spreadsheetnamezCreate a new Google Spreadsheet with the specified title and properties. Can optionally populate the spreadsheet with initial data.r   args_schemaNr   r   r   r   r   r   run_managerreturnc           
      6   | j                          	 | j                         }d||||di}	|j                         j                  |	d      j	                         }
|
j                  d      }|
j                  d      }|
j                  di       }d|||j                  d|      |j                  d	|      |j                  d
|      |j                  d|      dd}|rt	 t        |xs d      }d|i}|j                         j                         j                  ||d|      j	                         }d|d<   |j                  dd      |d<   ||d<   |S |S # t        $ r}t        |      |d<   d|d<   Y d}~|S d}~ww xY w# t        $ r}t        d|       |d}~ww xY w)a  Create a new Google Spreadsheet.

        Args:
            title: Title of the new spreadsheet.
            locale: Locale of the spreadsheet.
            time_zone: Timezone of the spreadsheet.
            auto_recalc: Recalculation setting.
            initial_data: Optional 2D array of initial data to populate.
            initial_range: Range where initial data should be placed.
            run_manager: Optional callback manager.

        Returns:
            success (bool): Whether operation succeeded.
            spreadsheet_id (str): Unique ID of created spreadsheet.
            spreadsheet_url (str): Direct URL to spreadsheet.
            title (str): Spreadsheet title.
            locale (str): Locale setting.
            time_zone (str): Timezone setting.
            auto_recalc (str): Recalculation setting.
            created (bool): Whether creation succeeded.
            initial_data_added (bool): Whether initial data was added.
            initial_data_cells_updated (int): Number of cells updated.
            initial_data_range (str): Range where data was placed.

        Raises:
            ValueError: If write permissions unavailable or validation fails.
            Exception: If API call fails.
        
properties)r   r   timeZone
autoRecalcz'spreadsheetId,spreadsheetUrl,properties)bodyfieldsspreadsheetIdspreadsheetUrlTr   r   r.   r/   )successspreadsheet_idspreadsheet_urlr   r   r   r   createdr   valuesRAW)r2   rangevalueInputOptionr0   initial_data_addedupdatedCellsr   initial_data_cells_updatedinitial_data_rangeinitial_data_errorFNzError creating spreadsheet: )_check_write_permissions_get_servicespreadsheetscreateexecutegetr   r8   update	Exceptionr    )selfr   r   r   r   r   r   r*   servicespreadsheet_bodyspreadsheetr5   r6   r-   resultvalidated_ranger0   update_resulteerrors                       r$   _runz SheetsCreateSpreadsheetTool._run   s   N 	%%'I	O'')G "$ )"-	  $$&)D     )___=N)oo.>?O$r:J  "0#2#7$..6:'^^J	B)~~lKH	F 9&9-:O4&PO$l3D  ,,.*8"1-2!%	    ! " 48F/0;H;L;L&<F78 4AF/0 M6M ! 936q6F/038F/0M9  	O:5'BCN	OsI   C	E; A1E E; E; 	E8E3-E; 3E88E; ;	FFF)r   r   r   Nr   N)r   r   r   r   r(   r    r!   r   r   r)   r   r	   r   r   r   r   r   rR   r"   r#   r$   r&   r&   >   s    JX ,D#+	E   $;Ki:
 !(#5%026'+;?rOrO rO C=	rO
 c]rO tDI/rO  }rO 78rO 
c3hrOr#   r&   N)r   typingr   r   r   r   r   langchain_core.callbacksr   pydanticr	   r
   baser   utilsr   r   r&   r"   r#   r$   <module>rX      s7    0 2 2 > %   &&i &\FO. FOr#   