o
    i                  	   @   s  d dl mZ d dlZd dlZd dlZd dlZd dlmZmZm	Z	 d dl
mZ ddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZmZ ddlmZmZ edZ	d5de	ee ef e!f deee ef  dee ef fddZ"	d5de	ee ef e!f deee ef  dee ef fddZ#	d5de	ee ef e!f deee ef  dee ef fddZ$	d5de	ee ef e!f deee ef  dee ef fddZ%	d5de	ee ef e!f deee ef  dee ef fddZ&	d5de	ee ef e!f deee ef  dee ef fddZ'	d5de	ee ef e!f deee ef  dee ef fdd Z(	d5de	ee ef e!f deee ef  dee ef fd!d"Z)	d5de	ee ef e!f deee ef  dee ef fd#d$Z*	d5de	ee ef e!f deee ef  dee ef fd%d&Z+	d5de	ee ef e!f deee ef  dee ef fd'd(Z,	d5de	ee ef e!f deee ef  dee ef fd)d*Z-	d5de	ee ef e!f deee ef  dee ef fd+d,Z.	d5de	ee ef e!f deee ef  dee ef fd-d.Z/	d5de	ee ef e!f deee ef  dee ef fd/d0Z0G d1d2 d2ej1Z2G d3d4 d4ej1Z3dS )6    )cached_propertyN)AnyOptionalUnion)	urlencode   )_api_module)_common)_extra_utils)types)get_value_by_path)set_value_by_path),_UploadToFileSearchStoreOperation_from_mldev)AsyncDocuments	Documents)
AsyncPagerPagerzgoogle_genai.filesearchstoresfrom_objectparent_objectreturnc                 C   s.   i }t | dgd urt|dgt | dg |S )Ndisplay_namedisplayNamegetvsetvr   r   	to_object r   e/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/google/genai/file_search_stores.py%_CreateFileSearchStoreConfig_to_mldev(   s   r   c                 C   *   i }t | dgd urtt | dg| |S Nconfig)r   r   r   r   r   r   )_CreateFileSearchStoreParameters_to_mldev4      r#   c                 C   s0   i }t | dgd urt|ddgt | dg |S )Nforce_queryr   r   r   r   r   %_DeleteFileSearchStoreConfig_to_mldevA   s   r'   c                 C   R   i }t | dgd urt|ddgt | dg t | dgd ur'tt | dg| |S )Nname_urlr"   )r   r   r'   r   r   r   r   )_DeleteFileSearchStoreParameters_to_mldevM   s   r+   c                 C   s0   i }t | dgd urt|ddgt | dg |S )Nr)   r*   r   r   r   r   r   &_GetFileSearchStoreParameters_to_mldev]   s   r,   c                 C   s^   i }t | dgd urt|dgdd t | dgD  t | dgd ur-t|dgt | dg |S )Ncustom_metadatacustomMetadatac                 S      g | ]}|qS r   r   .0itemr   r   r   
<listcomp>r       z._ImportFileConfig_to_mldev.<locals>.<listcomp>chunking_configchunkingConfigr   r   r   r   r   _ImportFileConfig_to_mldevh   s   
r7   c                 C   s   i }t | dgd urt|dgt | dg t | dgd ur(t|dgt | dg t | dgd ur;t|dgt | dg t | dgd urNt|dgt | dg t | dgd urdt|dgtt | dg| |S )Nr)   metadatadoneerrorresponse)r   r   _ImportFileResponse_from_mldevr   r   r   r   _ImportFileOperation_from_mldev   s$   r=   c                 C   sx   i }t | dgd urt|ddgt | dg t | dgd ur)t|dgt | dg t | dgd ur:tt | dg| |S )Nfile_search_store_namer*   	file_namefileNamer"   )r   r   r7   r   r   r   r   _ImportFileParameters_to_mldev   s   
rA   c                 C   sz   i }t | dgd urt|dgt | dg t | dgd ur(t|dgt | dg t | dgd ur;t|dgt | dg |S )NsdkHttpResponsesdk_http_responseparentdocumentNamedocument_namer   r   r   r   r   r<      s   r<   c                 C   sX   i }t | dgd urt|ddgt | dg t | dgd ur*t|ddgt | dg |S )N	page_sizer&   pageSize
page_token	pageTokenr   r   r   r   r   $_ListFileSearchStoresConfig_to_mldev   s   
rK   c                 C   r    r!   )r   rK   r   r   r   r   (_ListFileSearchStoresParameters_to_mldev   r$   rL   c                 C   s   i }t | dgd urt|dgt | dg t | dgd ur(t|dgt | dg t | dgd ur@t|dgdd t | dgD  |S )	NrB   rC   nextPageTokennext_page_tokenfileSearchStoresfile_search_storesc                 S   r/   r   r   r0   r   r   r   r3      r4   z<_ListFileSearchStoresResponse_from_mldev.<locals>.<listcomp>r   r   r   r   r   (_ListFileSearchStoresResponse_from_mldev   s   rQ   c                 C   s   i }t | dgd urt|dgt | dg t | dgd ur(t|dgt | dg t | dgd ur@t|dgdd t | dgD  t | d	gd urSt|d
gt | d	g |S )N	mime_typemimeTyper   r   r-   r.   c                 S   r/   r   r   r0   r   r   r   r3     r4   z;_UploadToFileSearchStoreConfig_to_mldev.<locals>.<listcomp>r5   r6   r   r   r   r   r   '_UploadToFileSearchStoreConfig_to_mldev   s$   
rT   c                 C   r(   )Nr>   r*   r"   )r   r   rT   r   r   r   r   +_UploadToFileSearchStoreParameters_to_mldev  s   
rU   c                 C   s.   i }t | dgd urt|dgt | dg |S )NrB   rC   r   r   r   r   r   4_UploadToFileSearchStoreResumableResponse_from_mldev.  s   rV   c                	   @   N  e Zd ZedefddZdddeej dej	fddZ
ddd	edeej dej	fd
dZddd	edeej ddfddZdddeej dejfddZdddedeej dejfddZdddededeej dejfddZdddedeeeje ejf deej dejfddZdddeej de ej	 fddZ!dS )FileSearchStoresr   c                 C   
   t | jS N)r   _api_clientselfr   r   r   	documents=     
zFileSearchStores.documentsNr"   r"   c                C   s   t j|d}| jjrtdt|}|d}|rd|}nd}|d}|r1| dt| }|	dd d}|j
durH|j
jdurH|j
j}t|}t|}| jd	|||}|js`i nt|j}	t jj|	| d
}
| j|
 |
S zCreates a File Search Store.

    Args:
      config (CreateFileSearchStoreConfig | None): Optional parameters for the
        request.

    Returns:
      FileSearchStore
    r`   =This method is only supported in the Gemini Developer client.r*   rO   r&   ?r"   Npostr;   kwargs)r    _CreateFileSearchStoreParametersr[   vertexai
ValueErrorr#   get
format_mapr   popr"   http_optionsr	   convert_to_dictencode_unserializable_typesrequestbodyjsonloadsFileSearchStore_from_response
model_dump_verify_responser]   r"   parameter_modelrequest_dictrequest_url_dictpathquery_paramsrm   r;   response_dictreturn_valuer   r   r   createA  s>   




zFileSearchStores.creater)   c                C   s   t j||d}| jjrtdt|}|d}|r d|}nd}|d}|r2| dt| }|	dd d}|j
durI|j
jdurI|j
j}t|}t|}| jd	|||}	|	jsai nt|	j}
t jj|
| d
}| j| |S aR  Gets metadata about a FileSearchStore.

    Args:
      name (str): The resource name of the FileSearchStore. Example:
        `FileSearchStores/my-file-search-store-123`
      config (GetFileSearchStoreConfig | None): Optional parameters for the
        request.

    Returns:
      A FileSearchStore object containing the metadata.
    r)   r"   rb   r*   {name}r&   rc   r"   Nrj   re   )r   _GetFileSearchStoreParametersr[   rh   ri   r,   rj   rk   r   rl   r"   rm   r	   rn   ro   rp   rq   rr   rs   rt   ru   rv   rw   r]   r)   r"   ry   rz   r{   r|   r}   rm   r;   r~   r   r   r   r   rj   |  s<   




zFileSearchStores.getc          
      C   s   t j||d}| jjrtdt|}|d}|r d|}nd}|d}|r2| dt| }|	dd d}|j
durI|j
jdurI|j
j}t|}t|}| jd	|||}	dS 
a  Deletes a FileSearchStore.

    Args:
      name (str): The resource name of the FileSearchStore. Example:
        `FileSearchStores/my-file-search-store-123`
      config (DeleteFileSearchStoreConfig | None): Optional parameters for the
        request.

    Returns:
      None
    r   rb   r*   r   r&   rc   r"   Ndelete)r    _DeleteFileSearchStoreParametersr[   rh   ri   r+   rj   rk   r   rl   r"   rm   r	   rn   ro   rp   
r]   r)   r"   ry   rz   r{   r|   r}   rm   r;   r   r   r   r     s4   




zFileSearchStores.deletec                C   s   t j|d}| jjrtdt|}|d}|rd|}nd}|d}|r1| dt| }|	dd d}|j
durH|j
jdurH|j
j}t|}t|}| jd	|||}|js`i nt|j}	| jjsnt|	}	t jj|	| d
}
| j|
 |
S a  Lists all FileSearchStore owned by the user.

    Args:
      config (ListFileSearchStoresConfig | None): Optional parameters for the
        request, such as page_size.

    Returns:
      ListFileSearchStoresResponse: A paginated list of FileSearchStore.
    r`   rb   r*   rO   r&   rc   r"   Nrj   re   )r   _ListFileSearchStoresParametersr[   rh   ri   rL   rj   rk   r   rl   r"   rm   r	   rn   ro   rp   rq   rr   rs   rQ   ListFileSearchStoresResponseru   rv   rw   rx   r   r   r   _list  s>   




zFileSearchStores._listr>   c                C   s2  t j||d}| jjrtdt|}|d}|r d|}nd}|d}|r2| dt| }|	dd  d }|j
d urI|j
jd urI|j
j}t|}t|}| jd|||}	|d urtt|d	d rtt j|	d
}
| j|
 |
S |	jsyi nt|	j}| jjst|}t jj|| d}
| j|
 |
S Nr>   r"   rb   r*   z>upload/v1beta/{file_search_store_name}:uploadToFileSearchStorer&   rc   r"   rd   should_return_http_response)rC   re   )r   "_UploadToFileSearchStoreParametersr[   rh   ri   rU   rj   rk   r   rl   r"   rm   r	   rn   ro   rp   getattr(UploadToFileSearchStoreResumableResponserw   rq   rr   rs   rV   ru   rv   r]   r>   r"   ry   rz   r{   r|   r}   rm   r;   r   r~   r   r   r   _upload_to_file_search_store/  sb   





z-FileSearchStores._upload_to_file_search_storer?   c                C   s  t j|||d}| jjrtdt|}|d}|r!d|}nd}|d}|r3| dt| }|	dd d}	|j
durJ|j
jdurJ|j
j}	t|}t|}| jd	|||	}
|
jsbi nt|
j}| jjspt|}t jj|| d
}| j| |S a  Imports a File from File Service to a FileSearchStore.

    This is a long-running operation, see aip.dev/151

    Args:
      file_search_store_name (str): The resource name of the FileSearchStore.
        Example: `fileSearchStores/my-file-search-store-123`
      file_name (str): The resource name of the File to import. Example:
        `files/abc-123`
      config (ImportFileConfig | None): Optional parameters for the request.

    Returns:
      ImportFileOperation.
    )r>   r?   r"   rb   r*   z#{file_search_store_name}:importFiler&   rc   r"   Nrd   re   )r   _ImportFileParametersr[   rh   ri   rA   rj   rk   r   rl   r"   rm   r	   rn   ro   rp   rq   rr   rs   r=   ImportFileOperationru   rv   rw   r]   r>   r?   r"   ry   rz   r{   r|   r}   rm   r;   r~   r   r   r   r   import_filey  sJ   




zFileSearchStores.import_filefilec                C   sB  | j jrtd|du ri }nt|trt|}n|jdd}tj||d|dd\}}}i ||dd}| j	|t
jdi |d	}	|	jdu s]|	jjdu s]d
|	jjvrad|	jjvratdd
|	jjv rn|	jjd
 }
n|	jjd }
t|tjr| j j||
||d}nt|}| j j||
||d}t|j}t
jj|i dS )au  Calls the API to upload a file to the given file search store.

    Args:
      file_search_store_name: The resource name of the FileSearchStore. Example:
        `fileSearchStores/file-search-store-123`
      file: A path to the file or an `IOBase` object to be uploaded. If it's an
        IOBase object, it must be opened in blocking (the default) mode and
        binary mode. In other words, do not use non-blocking mode or text mode.
        The given stream must be seekable, that is, it must be able to call
        `seek()` on 'path'.
      config: Optional parameters to set `diplay_name`, `mime_type`, and others.
    rb   NTexclude_unsetrm   rR   user_http_optionsuser_mime_typerm   r   r   x-goog-upload-urlX-Goog-Upload-URL`Failed to upload file to file search store. Upload URL did not returned from the upload request.rm   re   r   )r[   rh   ri   
isinstancedictrv   r
   prepare_resumable_uploadrj   r   r   UploadToFileSearchStoreConfigrC   headersKeyErrorioIOBaseupload_fileosfspathr   rr    UploadToFileSearchStoreOperationru   r]   r>   r   r"   user_config_dictrm   
size_bytes_final_config_dictr;   
upload_urlupload_responsefs_pathr~   r   r   r   upload_to_file_search_store  s`   



z,FileSearchStores.upload_to_file_search_storec                C   s   t d| j| j|d|S )a  Lists FileSearchStores.

    Args:
      config (ListFileSearchStoresConfig): Optional configuration for the list
        request.

    Returns:
      A Pager object that contains one page of file search stores. When
      iterating over
      the pager, it automatically fetches the next page if there are more.

    Usage:

    .. code-block:: python
      for file_search_store in client.file_search_stores.list():
        print(f"file search store: {file_search_store.name} -
        {file_search_store.display_name}")
    rP   r`   )r   r   r]   r"   r   r   r   list  s   
zFileSearchStores.list)"__name__
__module____qualname__r   r   r^   r   r   !CreateFileSearchStoreConfigOrDictrt   r   strGetFileSearchStoreConfigOrDictrj   !DeleteFileSearchStoreConfigOrDictr    ListFileSearchStoresConfigOrDictr   r   #UploadToFileSearchStoreConfigOrDictr   r   ImportFileConfigOrDictr   r   r   r   PathLiker   r   r   r   r   r   r   r   r   r   rX   ;  s    
?
C
9
@
O
P
MrX   c                	   @   rW   )AsyncFileSearchStoresr   c                 C   rY   rZ   )r   r[   r\   r   r   r   r^   /  r_   zAsyncFileSearchStores.documentsNr`   r"   c                   s   t j|d}| jjrtdt|}|d}|r d|}nd}|d}|r2| dt| }|	dd d}|j
durI|j
jdurI|j
j}t|}t|}| jd	|||I dH }|jsdi nt|j}	t jj|	| d
}
| j|
 |
S ra   )r   rg   r[   rh   ri   r#   rj   rk   r   rl   r"   rm   r	   rn   ro   async_requestrq   rr   rs   rt   ru   rv   rw   rx   r   r   r   r   3  s@   





zAsyncFileSearchStores.creater)   c                   s   t j||d}| jjrtdt|}|d}|r!d|}nd}|d}|r3| dt| }|	dd d}|j
durJ|j
jdurJ|j
j}t|}t|}| jd	|||I dH }	|	jsei nt|	j}
t jj|
| d
}| j| |S r   )r   r   r[   rh   ri   r,   rj   rk   r   rl   r"   rm   r	   rn   ro   r   rq   rr   rs   rt   ru   rv   rw   r   r   r   r   rj   n  sB   





zAsyncFileSearchStores.getc          
         s   t j||d}| jjrtdt|}|d}|r!d|}nd}|d}|r3| dt| }|	dd d}|j
durJ|j
jdurJ|j
j}t|}t|}| jd	|||I dH }	dS r   )r   r   r[   rh   ri   r+   rj   rk   r   rl   r"   rm   r	   rn   ro   r   r   r   r   r   r     s6   




zAsyncFileSearchStores.deletec                   s  t j|d}| jjrtdt|}|d}|r d|}nd}|d}|r2| dt| }|	dd d}|j
durI|j
jdurI|j
j}t|}t|}| jd	|||I dH }|jsdi nt|j}	| jjsrt|	}	t jj|	| d
}
| j|
 |
S r   )r   r   r[   rh   ri   rL   rj   rk   r   rl   r"   rm   r	   rn   ro   r   rq   rr   rs   rQ   r   ru   rv   rw   rx   r   r   r   r     sD   





zAsyncFileSearchStores._listr>   c                   s:  t j||d}| jjrtdt|}|d}|r!d|}nd}|d}|r3| dt| }|	dd  d }|j
d urJ|j
jd urJ|j
j}t|}t|}| jd|||I d H }	|d urxt|d	d rxt j|	d
}
| j|
 |
S |	js}i nt|	j}| jjst|}t jj|| d}
| j|
 |
S r   )r   r   r[   rh   ri   rU   rj   rk   r   rl   r"   rm   r	   rn   ro   r   r   r   rw   rq   rr   rs   rV   ru   rv   r   r   r   r   r   %  sd   






z2AsyncFileSearchStores._upload_to_file_search_storer?   c                   s  t j|||d}| jjrtdt|}|d}|r"d|}nd}|d}|r4| dt| }|	dd d}	|j
durK|j
jdurK|j
j}	t|}t|}| jd	|||	I dH }
|
jsfi nt|
j}| jjstt|}t jj|| d
}| j| |S r   )r   r   r[   rh   ri   rA   rj   rk   r   rl   r"   rm   r	   rn   ro   r   rq   rr   rs   r=   r   ru   rv   rw   r   r   r   r   r   o  sL   





z!AsyncFileSearchStores.import_filer   c                   sV  | j jr	td|du ri }nt|trt|}n|jdd}tj||d|dd\}}}i ||dd}| j	|t
jdi |d	I dH }	|	jdu sa|	jjdu sad
|	jjvred|	jjvretdd
|	jjv rr|	jjd
 }
n|	jjd }
t|tjr| j j||
||dI dH }nt|}| j j||
||dI dH }t|j}t
jj|i dS )at  Calls the API to upload a file to the given file search store.

    Args:
      file_search_store_name: The resource name of the FileSearchStore. Example:
        `fileSearchStores/file-search-store-123`
      file: A path to the file or an `IOBase` object to be uploaded. If it's an
        IOBase object, it must be opened in blocking (the default) mode and
        binary mode. In other words, do not use non-blocking mode or text mode.
        The given stream must be seekable, that is, it must be able to call
        `seek()` on 'path'.
      config: Optional parameters to set `diplay_name`, `mime_type` and others.
    rb   NTr   rm   rR   r   r   r   r   r   r   r   re   r   )r[   rh   ri   r   r   rv   r
   r   rj   r   r   r   rC   r   r   r   r   async_upload_filer   r   r   rr   r   ru   r   r   r   r   r     sb   



z1AsyncFileSearchStores.upload_to_file_search_storec                   s    t d| j| j|dI dH |S )a(  Lists FileSearchStores asynchronously.

    Args:
      config (ListFileSearchStoresConfig): Optional configuration for the list
        request.

    Returns:
      A Pager object that contains one page of FileSearchStores. When iterating
      over
      the pager, it automatically fetches the next page if there are more.

    Usage:

    .. code-block:: python
      async for file_search_store in await client.file_search_stores.list():
        print(f"file search store: {file_search_store.name} -
        {file_search_store.display_name}")
    rP   r`   N)r   r   r   r   r   r   r     s   zAsyncFileSearchStores.list)"r   r   r   r   r   r^   r   r   r   rt   r   r   r   rj   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   -  s    
?
E
9
B
O
P
Mr   rZ   )4	functoolsr   r   rr   loggingr   typingr   r   r   urllib.parser    r   r	   r
   r   r   r   r   r   _operations_convertersr   r^   r   r   pagersr   r   	getLoggerloggerr   r   objectr   r#   r'   r+   r,   r7   r=   rA   r<   rK   rL   rQ   rT   rU   rV   
BaseModulerX   r   r   r   r   r   <module>   s  






























   u