
    ZTh                         d dl mZ d dlZd dlmZ d dlZd dlmZ d dl	m
Z
 d dlmZ d dlmZ erd dlmZ d dlZd d	lmZ d d
lmZ  G d de      Zy)    )annotationsN)TYPE_CHECKING)ChannelsLowLevelClient)DataLowLevelClient)ResourceBase)	cel_utils)datetime)
SiftClient)Channelc                       e Zd ZdZd fdZ	 	 	 	 ddZ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d	 	 	 	 	 	 	 	 	 	 	 dd	Zddddd	 	 	 	 	 	 	 	 	 	 	 dd
Z	 xZ
S )ChannelsAPIAsynca  High-level API for interacting with channels.

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

    All methods in this class use the Channel class from the low-level wrapper, which is a user-friendly
    representation of a channel using standard Python data structures and types.
    c                    t         |   |       t        | j                  j                        | _        t        | j                  j                        | _        y)zdInitialize the ChannelsAPI.

        Args:
            sift_client: The Sift client to use.
        )grpc_clientN)super__init__r   clientr   _low_level_clientr   _data_low_level_client)selfsift_client	__class__s     c/home/www/backend.miabetepe.com/venv/lib/python3.12/site-packages/sift_client/resources/channels.pyr   zChannelsAPIAsync.__init__    s@     	%!7DKKD[D[!\&8T[[E\E\&]#    c               x   K   | j                   j                  |       d{   }| j                  |      S 7 w)zGet a Channel.

        Args:
            channel_id: The ID of the channel.

        Returns:
            The Channel.
        )
channel_idN)r   get_channel_apply_client_to_instance)r   r   channels      r   getzChannelsAPIAsync.get*   s;      ..::j:QQ--g66 Rs    :8:N)asset_idnamename_contains
name_regexdescriptiondescription_containsactiverun_idrun_name
client_keycreated_beforecreated_aftermodified_beforemodified_afterorder_bylimitc               J  K   t        d |||fD              dkD  rt        d      t        d ||fD              dkD  rt        d      t        d ||fD              dkD  rt        d      t        d ||fD              dkD  rt        d	      g }|r%|j                  t        j                  d
|             |r&|j                  t        j                  d|             nu|r&|j                  t        j
                  d|             nM|rKt        |t        j                        r|j                  }|j                  t        j                  d|             |r&|j                  t        j                  d|             n'|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%|j                  t        j                  d|             dj                  |      }| j                  j                  |||       d{   }| j!                  |      S 7 w)a\  List channels with optional filtering.

        Args:
            asset_id: The asset ID to get.
            name: The name of the channel to get.
            name_contains: The partial name of the channel to get.
            name_regex: The regex name of the channel to get.
            description: The description of the channel to get.
            description_contains: The partial description of the channel to get.
            active: Whether the channel is active.
            run_id: The run ID to get.
            run_name: The name of the run to get.
            client_key: The client key of the run to get.
            created_before: The created date of the channel to get.
            created_after: The created date of the channel to get.
            modified_before: The modified date of the channel to get.
            modified_after: The modified date of the channel to get.
            order_by: How to order the retrieved channels.
            limit: How many channels to retrieve. If None, retrieves all matches.

        Returns:
            A list of Channels that matches the filter.
        c              3  2   K   | ]  }t        |        y wNbool.0xs     r   	<genexpr>z)ChannelsAPIAsync.list_.<locals>.<genexpr>e        B1tAwB      zBCannot provide more than one of name, name_contains, or name_regexc              3  2   K   | ]  }t        |        y wr2   r3   r5   s     r   r8   z)ChannelsAPIAsync.list_.<locals>.<genexpr>g   s     D1tAwDr:   z8Cannot provide both description and description_containsc              3  2   K   | ]  }t        |        y wr2   r3   r5   s     r   r8   z)ChannelsAPIAsync.list_.<locals>.<genexpr>i   s     @1tAw@r:   z4Cannot provide both created_before and created_afterc              3  2   K   | ]  }t        |        y wr2   r3   r5   s     r   r8   z)ChannelsAPIAsync.list_.<locals>.<genexpr>k   r9   r:   z6Cannot provide both modified_before and modified_afterr    r!   r$   r&   r'   r(   r)   created_datemodified_datez && )query_filterr.   max_resultsN)sum
ValueErrorappendcelequalscontains
isinstancerePatternpatternmatch	less_thangreater_thanjoinr   list_all_channels_apply_client_to_instances)r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   filter_parts
filter_strchannelss                       r   list_zChannelsAPIAsync.list_:   s    V B}j ABBQFabbD.B CDDqHWXX@ ?@@1DSTTB. ABBQFUVV

:x @A

64 89V] CD*bjj1'//
		&* =>

=+ FG!]<P QR

8V <=

8V <=

:x @A

< DEnn MN 0 0 OPo OP 0 0. QR[[.
//AA# B 
 

 ..x88
s   L	L#L!L#c                   K    | j                   di | d{   }t        |      dkD  rt        d      t        |      dk(  r|d   S y7 1w)a  Find a single channel matching the given query. Takes the same arguments as `list`. If more than one channel is found,
        raises an error.

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

        Returns:
            The Channel found or None.
        Nr;   z!Multiple channels found for queryr    )rV   lenrD   )r   kwargsrU   s      r   findzChannelsAPIAsync.find   sT      $-f--x=1@AA]aA; .s   AA
2A)r'   
start_timeend_timer/   c               ^   K   | j                   j                  |||||       d{   S 7 w)a  Get data for one or more channels.

        Args:
            channels: The channels to get data for.
            run_id: The run to get data for.
            start_time: The start time to get data for.
            end_time: The end time to get data for.
            limit: The maximum number of data points to return. Will be in increments of page_size or default page size defined by the call if no page_size is provided.
        rU   r'   r\   r]   r/   N)r   get_channel_data)r   rU   r'   r\   r]   r/   s         r   get_datazChannelsAPIAsync.get_data   s@     $ 00AA! B 
 
 	
 
s   $-+-c                  K   | j                  |||||       d{   }|j                         D ci c]%  \  }}|t        j                  j	                  |      ' c}}S 7 Ec c}}w w)z4Get data for one or more channels as pyarrow tables.r_   N)ra   itemspaTablefrom_pandas)	r   rU   r'   r\   r]   r/   datakvs	            r   get_data_as_arrowz"ChannelsAPIAsync.get_data_as_arrow   sk      ]]! # 
 
 8<zz|Dtq!288''**DD
 Es    A*A"A**A$A*$A*)r   r
   )r   strreturnr   )"r    
str | Noner!   rm   r"   rm   r#   zstr | re.Pattern | Noner$   rm   r%   rm   r&   zbool | Noner'   rm   r(   rm   r)   rm   r*   datetime | Noner+   rn   r,   rn   r-   rn   r.   rm   r/   
int | Nonerl   list[Channel])rl   zChannel | None)rU   rp   r'   rm   r\   rn   r]   rn   r/   ro   rl   zdict[str, pd.DataFrame])rU   rp   r'   rm   r\   rn   r]   rn   r/   ro   rl   zdict[str, pa.Table])__name__
__module____qualname____doc__r   r   rV   r[   ra   rj   __classcell__)r   s   @r   r   r      s   ^7 7 
	7&  $$(.2"&+/"!#!%*.)-+/*.# %[9 [9 	[9
 "[9 ,[9  [9 )[9 [9 [9 [9 [9 ([9 '[9 )[9  (![9" #[9$ %[9& 
'[9z* "&*$( 
  
 	

 $
 "
 
 
!
< "&*$( E  E 	E
 $E "E E 
Er   r   )
__future__r   rJ   typingr   pyarrowrd   1sift_client._internal.low_level_wrappers.channelsr   -sift_client._internal.low_level_wrappers.datar   sift_client.resources._baser   sift_client.utilr   rF   r	   pandaspdsift_client.clientr
   sift_client.sift_types.channelr   r   rX   r   r   <module>r      s<    " 	    T L 4 -!-6}E| }Er   