
    ZTh                        d dl mZ d dlZd dlmZmZ d dlmZ d dlm	Z	 erd dl
m
Z
 d dlmZ d dlmZ  ej                  e      Z G d	 d
e	      Zy)    )annotationsN)TYPE_CHECKINGAny)IngestionLowLevelClient)ResourceBase)datetime)
SiftClient)Flowc                  j     e Zd ZdZd fdZdddd	 	 	 	 	 	 	 	 	 	 	 d	dZ	 	 	 	 	 	 d
dZdddZ xZS )IngestionAPIAsynca  High-level API for interacting with ingestion services.

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

    All methods in this class use the Flow class from the types module, which is a user-friendly
    representation of ingestion flows using standard Python data structures and types.
    c                n    t         |   |       t        | j                  j                        | _        y)zeInitialize the IngestionAPI.

        Args:
            sift_client: The Sift client to use.
        )grpc_clientN)super__init__r   clientr   _low_level_client)selfsift_client	__class__s     d/home/www/backend.miabetepe.com/venv/lib/python3.12/site-packages/sift_client/resources/ingestion.pyr   zIngestionAPIAsync.__init__   s)     	%!8T[[E\E\!]    N)run_id
client_keyorganization_idc                  K   |st        d      |st        d      | j                  j                  ||||       d{   }|D ]'  }|j                  | j                         |s!||_        ) |S 7 2w)a  Create an ingestion config.

        Args:
            asset_name: The name of the asset for this ingestion config.
            run_id: Optionally provide a run ID to create a run for the given asset.
            flows: List of flow configurations.
            client_key: Optional client key for identifying this config.
            organization_id: The organization ID.

        Returns:
            The ingestion config ID.

        Raises:
            ValueError: If asset_name is not provided or flows is empty.
        zasset_name must be providedzflows must not be empty)
asset_nameflowsr   r   N)
ValueErrorr   create_ingestion_config_apply_client_to_instancer   r   )r   r   r   r   r   r   ingestion_config_idflows           r   r   z)IngestionAPIAsync.create_ingestion_config%   s     0 :;;677$($:$:$R$R!!+	 %S %
 
  	%D**4;;7$	%
 #"
s   =A4A2 &A4'A4c               @    | j                   j                  |||       y)zIngest data for a flow.

        Args:
            flow: The flow to ingest data for.
            timestamp: The timestamp of the data.
            channel_values: Dictionary mapping channel names to their values.
        )r"   	timestampchannel_valuesN)r   ingest_flow)r   r"   r$   r%   s       r   ingestzIngestionAPIAsync.ingestO   s&     	**) 	+ 	
r   c                d    t         j                  d       | j                  j                  |       y)zWait for all ingestion to complete.

        Args:
            run_id: The id of the run to wait for.
            timeout: The timeout in seconds to wait for ingestion to complete. If None, will wait forever.
        z!Waiting for ingestion to completeN)loggerinfor   wait_for_ingestion_to_complete)r   timeouts     r   r+   z0IngestionAPIAsync.wait_for_ingestion_to_completec   s%     	78==gFr   )r   r	   )r   strr   
str | Noner   z
list[Flow]r   r.   r   r.   returnr-   )r"   r
   r$   r   r%   zdict[str, Any])N)r,   zfloat | None)	__name__
__module____qualname____doc__r   r   r'   r+   __classcell__)r   s   @r   r   r      s    ^ "!%&*(# (# 	(#
 (# (# $(# 
(#T
 
 	

 '
(G Gr   r   )
__future__r   loggingtypingr   r   2sift_client._internal.low_level_wrappers.ingestionr   sift_client.resources._baser   r   sift_client.clientr	    sift_client.sift_types.ingestionr
   	getLoggerr0   r)   r    r   r   <module>r>      sB    "  % V 4!-5			8	$YG YGr   