
    ZTh                        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
mZ d dlmZ erd dlZd dlmZ d d	lmZ  G d
 de      Zy)    )annotations)TYPE_CHECKINGAny)AssetsLowLevelClient)ResourceBase)AssetAssetUpdate)	cel_utilsN)datetime)
SiftClientc                       e Zd ZdZd fdZddd	 	 	 	 	 ddZdddddddddddddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZdd	Zdd
ddZddZ	 xZ
S )AssetsAPIAsynca  High-level API for interacting with assets.

    This class provides a Pythonic, notebook-friendly interface for interacting with the AssetsAPI.
    It handles automatic handling of gRPC services, seamless type conversion, and clear error handling.

    All methods in this class use the Asset class from the low-level wrapper, which is a user-friendly
    representation of an asset using standard Python data structures and types.
    c                n    t         |   |       t        | j                  j                        | _        y)zbInitialize the AssetsAPI.

        Args:
            sift_client: The Sift client to use.
        )grpc_clientN)super__init__r   clientr   _low_level_client)selfsift_client	__class__s     a/home/www/backend.miabetepe.com/venv/lib/python3.12/site-packages/sift_client/resources/assets.pyr   zAssetsAPIAsync.__init__   s)     	%!5$++BYBY!Z    N)asset_idnamec                 K   |r$| j                   j                  |       d{   }n|r| j                   j                  t        j                  d|             d{   }t        |      dk  rt        d| d      t        |      dkD  rt        dt        |       d| d      |d	   }nt        d
      | j                  |      S 7 7 nw)zGet an Asset.

        Args:
            asset_id: The ID of the asset.
            name: The name of the asset.

        Returns:
            The Asset.
        Nr   )query_filter   zNo asset found with name ''
Multiple (z) assets found with name 'r   z(Either asset_id or name must be provided)r   	get_assetlist_all_assetsr
   equalslen
ValueError_apply_client_to_instance)r   r   r   assetassetss        r   getzAssetsAPIAsync.get$   s      00::8DDE11AA&--fd; B  F 6{Q #=dV1!EFF6{Q  V-GvQO  1IE GHH--e44# Es"   !CC:CCA-CCF)r   name_contains
name_regex	asset_idscreated_aftercreated_beforemodified_aftermodified_before
created_bymodified_bytagstag_idsmetadatainclude_archivedfilter_queryorder_bylimitc               2  K   |sg }|r%|j                  t        j                  d|             |r%|j                  t        j                  d|             |r%|j                  t        j                  d|             |r%|j                  t        j
                  d|             |r%|j                  t        j                  d|             |r%|j                  t        j                  d|             |r%|j                  t        j                  d|             |r%|j                  t        j                  d|             |	rt        |
rt        |r%|j                  t        j
                  d|             |r%|j                  t        j
                  d|             |rt        |s$|j                  t        j                  d             t        j                  | }| j                  j                  |||       d	{   }| j                  |      S 7 w)
a  List assets with optional filtering.

        Args:
            asset_ids: List of asset IDs to filter by.
            name: Exact name of the asset.
            name_contains: Partial name of the asset.
            name_regex: Regular expression string to filter assets by name.
            asset_ids: List of asset IDs to filter by.
            created_after: Created after this date.
            created_before: Created before this date.
            modified_after: Modified after this date.
            modified_before: Modified before this date.
            created_by: Assets created by this user.
            modified_by: Assets last modified by this user.
            tags: Assets with these tags.
            tag_ids: List of asset tag IDs to filter by.
            metadata: metadata filter
            include_archived: Include archived assets.
            filter_query: Explicit CEL query to filter assets.
            order_by: How to order the retrieved assets. # TODO: tooling for this?
            limit: How many assets to retrieve. If None, retrieves all matches.

        Returns:
            A list of Assets that matches the filter.

        r   r   created_datemodified_datetag_namer4   archived_date)r   r8   max_resultsN)appendr
   r#   containsmatchin_greater_than	less_thanNotImplementedErrorequals_nulland_r   r"   _apply_client_to_instances)r   r   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   filtersr(   s                       r   list_zAssetsAPIAsync.list_G   s    ^ Gy//=>y11&-HIyvzBCy}}ZCDy55nmTUy22>>RSy55o~VWy22?OTU))))y}}Z>?y}}Y@A))#y44_EF$>>73L--==% > 
 

 ..v66
s   G=H?H Hc                   K    | j                   di | d{   }t        |      dkD  rt        dt        |       d      t        |      dk(  r|d   S y7 >w)a  Find a single asset matching the given query. Takes the same arguments as `list_`. If more than one asset is found,
        raises an error.

        Args:
            **kwargs: Keyword arguments to pass to `list_`.

        Returns:
            The Asset found or None.
        Nr   r    z) assets found for queryr    )rK   r$   r%   )r   kwargsr(   s      r   findzAssetsAPIAsync.find   s`      "tzz+F++v;?z#f+6NOPP[A!9 ,s   AA?Aarchive_runsc                  K   t        |t              r|j                  xs dn|}| j                  j	                  |xs d|       d{    | j                  |       d{   S 7 7 w)zArchive an asset.

        Args:
             asset: The Asset or asset ID to archive.
             archive_runs: If True, archive all Runs associated with the Asset.

        Returns:
             The archived Asset.
         rP   N)r   )
isinstancer   id_r   delete_assetr)   )r   r'   rQ   r   s       r   archivezAssetsAPIAsync.archive   sa      '1&>599?E$$11(.b|1\\\XXxX000 	]0s$   AA,	A(
A,#A*$A,*A,c                  K   t        |t              r|j                  xs dn|}t        |t              rt	        j
                  |      }||_        | j                  j                  |       d{   }| j                  |      S 7 w)zUpdate an Asset.

        Args:
            asset: The Asset or asset ID to update.
            update: Updates to apply to the Asset.

        Returns:
            The updated Asset.

        rS   )updateN)
rT   r   rU   dictr	   model_validateresource_idr   update_assetr&   )r   r'   rY   r   s       r   rY   zAssetsAPIAsync.update   su      '1&>599?Efd# //7F%,,999HH--e44 Is   A.B0B1B)r   r   )r   
str | Noner   r^   returnr   )$r   r^   r*   r^   r+   zstr | re.Pattern | Noner,   list[str] | Noner-   datetime | Noner.   ra   r/   ra   r0   ra   r1   
Any | Noner2   rb   r3   r`   r4   r`   r5   zlist[Any] | Noner6   boolr7   r^   r8   r^   r9   z
int | Noner_   zlist[Asset])r_   zAsset | None)r'   str | AssetrQ   rc   r_   r   )r'   rd   rY   zAssetUpdate | dictr_   r   )__name__
__module____qualname____doc__r   r)   rK   rO   rW   rY   __classcell__)r   s   @r   r   r      sR   [  $	!5 !5 	!5
 
!5L  $(.2&*)-*.*.+/!%"&!%$(%)!&#'# 'T7 T7 "	T7
 ,T7 $T7 'T7 (T7 (T7 )T7 T7  T7 T7 "T7 #T7  !T7" !#T7$ %T7& 'T7( 
)T7l" IN 1 5r   r   )
__future__r   typingr   r   /sift_client._internal.low_level_wrappers.assetsr   sift_client.resources._baser   sift_client.sift_types.assetr   r	   sift_client.utilr
   rer   sift_client.clientr   r   rM   r   r   <module>rr      s1    " % P 4 ; &!-}5\ }5r   