
    ]j).                        d dl 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
 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  e j6                  e j8                  d      Z G d d      Z G d d      Zy)    N)JSONDecodeError   )ApiError)AsyncClientWrapperSyncClientWrapper)AsyncHttpResponseHttpResponse)RequestOptions)'convert_and_respect_annotation_metadata)construct_type   )CreateActionsRequestFilters)CreateActionsRequestId) CreateActionsRequestOrderingItem)!CreateActionsRequestSelectedItems)ListActionsResponseItem.c                   D   e Zd ZdefdZdddedej                  e   de	ej                  e      fdZdeeedd	d
ededej                  e   dej                  e   dej                  ej                   e      dej                  e   dej                  e   de	d   fdZy)RawActionsClientclient_wrapperc                    || _         y N_client_wrapperselfr   s     M/root/env/lib/python3.12/site-packages/label_studio_sdk/actions/raw_client.py__init__zRawActionsClient.__init__   
    -    Nrequest_optionsprojectr!   returnc                P   | j                   j                  j                  ddd|i|      }	 d|j                  cxk  rdk  rin nft	        j
                  t        j                  t           t        t        j                  t           |j                                     }t        ||      S |j                         }t        |j                  t        |j                        |	      # t        $ r6 t        |j                  t        |j                        |j                  	      w xY w)
a  
        Retrieve all the registered actions with descriptions that data manager can use.

        Parameters
        ----------
        project : int
            Project ID

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[typing.List[ListActionsResponseItem]]
            Actions retrieved successfully
        api/dm/actions/GETr"   methodparamsr!      ,  type_object_responsedatastatus_codeheadersbody)r   httpx_clientrequestr3   typingcastListr   r   jsonr	   r   r   dictr4   textr   r"   r!   	_response_data_response_jsons         r   listzRawActionsClient.list   s   & ((55==7 , > 
		ti++1c1KK 78"$kk*AB ) 0 $YUCC&^^-N 9#8#8$yGXGXBY`noo  	ty'<'<d9K\K\F]dmdrdrss	ts   A=C& +C& &?D%viewfiltersorderingselected_itemsr!   idrD   rE   rF   rG   c                   | j                   j                  j                  dd|||dt        |t        d      |t        |t
        d      dddi|t        	      }	 d
|j                  cxk  rdk  rn nt        |d      S |j                         }	t        |j                  t        |j                        |	      # t        $ r6 t        |j                  t        |j                        |j                        w xY w)aJ  
        Perform a Data Manager action with the selected tasks and filters. Note: More complex actions require additional parameters in the request body. Call `GET api/actions?project=<id>` to explore them. <br>Example: `GET api/actions?id=delete_tasks&project=1`

        Parameters
        ----------
        id : CreateActionsRequestId
            Action name ID, see the full list of actions in the `GET api/actions` request

        project : int
            Project ID

        view : typing.Optional[int]
            View ID (optional, it has higher priority than filters, selectedItems and ordering from the request body payload)

        filters : typing.Optional[CreateActionsRequestFilters]
            Filters to apply on tasks. You can use [the helper class `Filters` from this page](https://labelstud.io/sdk/data_manager.html) to create Data Manager Filters.<br>Example: `{"conjunction": "or", "items": [{"filter": "filter:tasks:completed_at", "operator": "greater", "type": "Datetime", "value": "2021-01-01T00:00:00.000Z"}]}`

        ordering : typing.Optional[typing.Sequence[CreateActionsRequestOrderingItem]]
            List of fields to order by. Fields are similar to filters but without the `filter:` prefix. To reverse the order, add a minus sign before the field name, e.g. `-tasks:created_at`.

        selected_items : typing.Optional[CreateActionsRequestSelectedItems]
            Task selection by IDs. If filters are applied, the selection will be applied to the filtered tasks.If "all" is `false`, `"included"` must be used. If "all" is `true`, `"excluded"` must be used.<br>Examples: `{"all": false, "included": [1, 2, 3]}` or `{"all": true, "excluded": [4, 5]}`

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[None]
        r%   POSTrH   r"   rD   writer.   
annotation	directionrE   rF   selectedItemscontent-typeapplication/jsonr(   r)   r;   r4   r!   omitr*   r+   Nr/   r2   )r   r6   r7   r   r   r   OMITr3   r	   r;   r   r   r<   r4   r=   
r   rH   r"   rD   rE   rF   rG   r!   r?   rA   s
             r   createzRawActionsClient.createD   s   R ((55==" C#0KW^ %!H*7Xdk"  2 ,+ > 
	.	ti++1c1#YTBB&^^-N 9#8#8$yGXGXBY`noo  	ty'<'<d9K\K\F]dmdrdrss	ts   $B< B< <?C;)__name__
__module____qualname__r   r   intr8   Optionalr
   r	   r:   r   rB   rV   r   r   Sequencer   r   rX    r   r   r   r      s   .*; . SW(p(p060O(p	fkk"9:	;(p^ &*@DW[MQ;?Fp #Fp 	Fp
 ooc"Fp !<=Fp //&//2R"STFp (IJFp  8Fp 
d	Fpr   r   c                   D   e Zd ZdefdZdddedej                  e   de	ej                  e      fdZdeeedd	d
ededej                  e   dej                  e   dej                  ej                   e      dej                  e   dej                  e   de	d   fdZy)AsyncRawActionsClientr   c                    || _         y r   r   r   s     r   r   zAsyncRawActionsClient.__init__   r   r   Nr    r"   r!   r#   c                l  K   | j                   j                  j                  ddd|i|       d{   }	 d|j                  cxk  rdk  rin nft	        j
                  t        j                  t           t        t        j                  t           |j                                     }t        ||	      S |j                         }t        |j                  t        |j                        |
      7 # t        $ r6 t        |j                  t        |j                        |j                  
      w xY ww)a  
        Retrieve all the registered actions with descriptions that data manager can use.

        Parameters
        ----------
        project : int
            Project ID

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[typing.List[ListActionsResponseItem]]
            Actions retrieved successfully
        r%   r&   r"   r'   Nr*   r+   r,   r/   r2   )r   r6   r7   r3   r8   r9   r:   r   r   r;   r   r   r   r<   r4   r=   r>   s         r   rB   zAsyncRawActionsClient.list   s    & ..;;CC7 , D 
 
		ti++1c1KK 78"$kk*AB ) 0 ))%HH&^^-N 9#8#8$yGXGXBY`noo+
&  	ty'<'<d9K\K\F]dmdrdrss	ts3   /D4C0D4A=C2 4D45C2 ,D42?D11D4rC   rH   rD   rE   rF   rG   c                  K   | j                   j                  j                  dd|||dt        |t        d      |t        |t
        d      dddi|t        	       d
{   }	 d|j                  cxk  rdk  rn nt        |d
      S |j                         }	t        |j                  t        |j                        |	      7 e# t        $ r6 t        |j                  t        |j                        |j                        w xY ww)aO  
        Perform a Data Manager action with the selected tasks and filters. Note: More complex actions require additional parameters in the request body. Call `GET api/actions?project=<id>` to explore them. <br>Example: `GET api/actions?id=delete_tasks&project=1`

        Parameters
        ----------
        id : CreateActionsRequestId
            Action name ID, see the full list of actions in the `GET api/actions` request

        project : int
            Project ID

        view : typing.Optional[int]
            View ID (optional, it has higher priority than filters, selectedItems and ordering from the request body payload)

        filters : typing.Optional[CreateActionsRequestFilters]
            Filters to apply on tasks. You can use [the helper class `Filters` from this page](https://labelstud.io/sdk/data_manager.html) to create Data Manager Filters.<br>Example: `{"conjunction": "or", "items": [{"filter": "filter:tasks:completed_at", "operator": "greater", "type": "Datetime", "value": "2021-01-01T00:00:00.000Z"}]}`

        ordering : typing.Optional[typing.Sequence[CreateActionsRequestOrderingItem]]
            List of fields to order by. Fields are similar to filters but without the `filter:` prefix. To reverse the order, add a minus sign before the field name, e.g. `-tasks:created_at`.

        selected_items : typing.Optional[CreateActionsRequestSelectedItems]
            Task selection by IDs. If filters are applied, the selection will be applied to the filtered tasks.If "all" is `false`, `"included"` must be used. If "all" is `true`, `"excluded"` must be used.<br>Examples: `{"all": false, "included": [1, 2, 3]}` or `{"all": true, "excluded": [4, 5]}`

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[None]
        r%   rJ   rK   rL   rM   rP   rR   rS   rT   Nr*   r+   r/   r2   )r   r6   r7   r   r   r   rV   r3   r   r;   r   r   r<   r4   r=   rW   s
             r   rX   zAsyncRawActionsClient.create   s    R ..;;CC" C#0KW^ %!H*7Xdk"  2 ,+ D 
 
	.	ti++1c1()$GG&^^-N 9#8#8$yGXGXBY`noo;
6  	ty'<'<d9K\K\F]dmdrdrss	ts6   AD
 C!D
&$C 
D
C ,D
?DD
)rY   rZ   r[   r   r   r\   r8   r]   r
   r   r:   r   rB   rV   r   r   r^   r   r   rX   r_   r   r   ra   ra      s   .*< . SW(p(p060O(p	6;;'>?	@(p^ &*@DW[MQ;?Fp #Fp 	Fp
 ooc"Fp !<=Fp //&//2R"STFp (IJFp  8Fp 
4	 Fpr   ra   ) r8   json.decoderr   core.api_errorr   core.client_wrapperr   r   core.http_responser   r	   core.request_optionsr
   core.serializationr   core.unchecked_base_modelr   $types.create_actions_request_filtersr   types.create_actions_request_idr   *types.create_actions_request_ordering_itemr   +types.create_actions_request_selected_itemsr    types.list_actions_response_itemr   r9   AnyrV   r   ra   r_   r   r   <module>rr      sc     ( % G @ 1 H 6 M C X Z E v{{6::s#tp tpntp tpr   