
    ]jW                         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  e j2                  e j4                  d      Z G d d      Z G d d      Zy)    N)JSONDecodeError   )ApiError)AsyncClientWrapperSyncClientWrapper)AsyncHttpResponseHttpResponse)jsonable_encoder)RequestOptions)construct_type)ActionsEnum)Webhook)WebhookSerializerForUpdate   )InfoWebhooksResponse.c                      e Zd ZdefdZddddej                  e   dej                  e   de	ej                  e      fdZeeeeeedd	d
edej                  ej                  e      dej                  ej                      dej                  e   dej                  e   dej                  e   dej                  e   dej                  e   de	e   fdZddddej                  e   dej                  e   de	e   fdZdddedej                  e   de	e   fdZdddedej                  e   de	d   fdZeeeeeedddedej                  ej                  e      dej                  ej                      dej                  e   dej                  e   dej                  e   d
ej                  e   dej                  e   de	e   fdZy)RawWebhooksClientclient_wrapperc                    || _         y N_client_wrapperselfr   s     N/root/env/lib/python3.12/site-packages/label_studio_sdk/webhooks/raw_client.py__init__zRawWebhooksClient.__init__   
    -    Nprojectrequest_optionsr    r!   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)
aZ  
        List all webhooks set up for your organization.

        Parameters
        ----------
        project : typing.Optional[str]
            Project ID

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

        Returns
        -------
        HttpResponse[typing.List[Webhook]]

        api/webhooks/GETr    methodparamsr!      ,  type_object_responsedatastatus_codeheadersbody)r   httpx_clientrequestr2   typingcastListr   r   jsonr	   r   r   dictr3   textr   r    r!   	_response_data_response_jsons         r   listzRawWebhooksClient.list   s   & ((55==7 , > 
		ti++1c1KK("$kk'2 ) 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%actionsr3   	is_activer    send_for_all_actionssend_payloadr!   urlrC   r3   rD   rE   rF   c                (   | j                   j                  j                  dd|||||||dddi|t              }		 d|	j                  cxk  rdk  rGn nDt        j                  t        t        t        |	j                         	            }
t        |	|

      S |	j                         }t        |	j                  t        |	j                        |      # t        $ r6 t        |	j                  t        |	j                        |	j                        w xY w)a/  
        Create a webhook for your organization.

        Parameters
        ----------
        url : str
            URL of webhook

        actions : typing.Optional[typing.Sequence[ActionsEnum]]

        headers : typing.Optional[typing.Any]
            Key Value Json of headers

        is_active : typing.Optional[bool]
            If value is False the webhook is disabled

        project : typing.Optional[int]

        send_for_all_actions : typing.Optional[bool]
            If value is False - used only for actions from WebhookAction

        send_payload : typing.Optional[bool]
            If value is False send only action

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

        Returns
        -------
        HttpResponse[Webhook]

        r$   POSTrC   r3   rD   r    rE   rF   rG   content-typeapplication/jsonr'   r:   r3   r!   omitr)   r*   r+   r.   r1   )r   r5   r6   OMITr2   r7   r8   r   r   r:   r	   r   r   r;   r3   r<   r   rG   rC   r3   rD   r    rE   rF   r!   r>   r?   r@   s               r   createzRawWebhooksClient.createC   s   X ((55==""&"(< ,  2 ,! > 
	$	ti++1c1"% ) 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organization_onlyr!   rS   c                   | j                   j                  j                  ddd|i|      }	 d|j                  cxk  rdk  rGn nDt	        j
                  t        t        t        |j                                     }t        ||      S |j                         }t        |j                  t        |j                        |	      # t        $ r6 t        |j                  t        |j                        |j                  	      w xY w)
a  
        Get descriptions of all available webhook actions to set up webhooks.

        Parameters
        ----------
        organization_only : typing.Optional[bool]
            organization-only or not

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

        Returns
        -------
        HttpResponse[InfoWebhooksResponse]
            Object with webhook action descriptions.
        api/webhooks/info/r%   organization-onlyr&   r)   r*   r+   r.   r1   )r   r5   r6   r2   r7   r8   r   r   r:   r	   r   r   r;   r3   r<   r   rS   r!   r>   r?   r@   s         r   infozRawWebhooksClient.info   s    , ((55== #%6 , > 
		ti++1c1("2 ) 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r!   idc                    | j                   j                  j                  dt        |       dd|      }	 d|j                  cxk  rdk  rGn nDt        j                  t        t        t        |j                                     }t        ||      S |j                         }t        |j                  t        |j                        |	      # t        $ r6 t        |j                  t        |j                        |j                  	      w xY w)
z
        Parameters
        ----------
        id : int

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

        Returns
        -------
        HttpResponse[Webhook]

        r$   /r%   r'   r!   r)   r*   r+   r.   r1   )r   r5   r6   r
   r2   r7   r8   r   r   r:   r	   r   r   r;   r3   r<   r   rZ   r!   r>   r?   r@   s         r   getzRawWebhooksClient.get   s     ((55==,R013+ > 
	
	ti++1c1"% ) 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c                   | j                   j                  j                  dt        |       dd|      }	 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)
z
        Parameters
        ----------
        id : int

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

        Returns
        -------
        HttpResponse[None]
        r$   r\   DELETEr]   r)   r*   Nr.   r1   )r   r5   r6   r
   r2   r	   r:   r   r   r;   r3   r<   r   rZ   r!   r>   r@   s        r   deletezRawWebhooksClient.delete   s     ((55==,R013+ > 
	
	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rC   r3   rD   rE   rF   rG   r!   c                @   | j                   j                  j                  dt        |       dd||||||dddi|t              }		 d|	j
                  cxk  rd	k  rGn nDt        j                  t        t        t        |	j                         
            }
t        |	|
      S |	j                         }t        |	j
                  t        |	j                        |      # t        $ r6 t        |	j
                  t        |	j                        |	j                         w xY w)a  
        Parameters
        ----------
        id : int

        actions : typing.Optional[typing.Sequence[ActionsEnum]]

        headers : typing.Optional[typing.Any]
            Key Value Json of headers

        is_active : typing.Optional[bool]
            If value is False the webhook is disabled

        send_for_all_actions : typing.Optional[bool]
            If value is False - used only for actions from WebhookAction

        send_payload : typing.Optional[bool]
            If value is False send only action

        url : typing.Optional[str]
            URL of webhook

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

        Returns
        -------
        HttpResponse[WebhookSerializerForUpdate]

        r$   r\   PATCHrC   r3   rD   rE   rF   rG   rK   rL   rM   r)   r*   r+   r.   r1   )r   r5   r6   r
   rO   r2   r7   r8   r   r   r:   r	   r   r   r;   r3   r<   r   rZ   rC   r3   rD   rE   rF   rG   r!   r>   r?   r@   s               r   updatezRawWebhooksClient.update   s   T ((55==,R013""&(< ,  2 , > 
	"	ti++1c1."8 ) 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)__name__
__module____qualname__r   r   r7   Optionalstrr   r	   r9   r   rA   rO   Sequencer   AnyboolintrQ   r   rX   r_   rc   r   ri    r   r   r   r      s   .*; . 26jn(p //#.(pHNXfHg(p	fkk'*	+(p\ BF/3+/(,6:.2;?Kp Kp !=>	Kp
 ,Kp ??4(Kp %Kp %ood3Kp ood+Kp  8Kp 
g	Kp` 48;?	+p "??40+p  8	+p
 
*	++pZ RV  pc  pv~/N  pZfgnZo  pD UY p p&//.2Q p]ijn]o p< BF/3+/6:.2$(;?HpHp !=>	Hp
 ,Hp ??4(Hp %ood3Hp ood+Hp __S!Hp  8Hp 
0	1Hpr   r   c                      e Zd ZdefdZddddej                  e   dej                  e   de	ej                  e      fdZeeeeeedd	d
edej                  ej                  e      dej                  ej                      dej                  e   dej                  e   dej                  e   dej                  e   dej                  e   de	e   fdZddddej                  e   dej                  e   de	e   fdZdddedej                  e   de	e   fdZdddedej                  e   de	d   fdZeeeeeedddedej                  ej                  e      dej                  ej                      dej                  e   dej                  e   dej                  e   d
ej                  e   dej                  e   de	e   fdZy)AsyncRawWebhooksClientr   c                    || _         y r   r   r   s     r   r   zAsyncRawWebhooksClient.__init__E  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_  
        List all webhooks set up for your organization.

        Parameters
        ----------
        project : typing.Optional[str]
            Project ID

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

        Returns
        -------
        AsyncHttpResponse[typing.List[Webhook]]

        r$   r%   r    r&   Nr)   r*   r+   r.   r1   )r   r5   r6   r2   r7   r8   r9   r   r   r:   r   r   r   r;   r3   r<   r=   s         r   rA   zAsyncRawWebhooksClient.listH  s    & ..;;CC7 , D 
 
		ti++1c1KK("$kk'2 ) 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rB   rG   rC   r3   rD   rE   rF   c                D  K   | j                   j                  j                  dd|||||||dddi|t               d{   }		 d|	j                  cxk  rd	k  rGn nDt        j                  t        t        t        |	j                         
            }
t        |	|
      S |	j                         }t        |	j                  t        |	j                        |      7 # t        $ r6 t        |	j                  t        |	j                        |	j                        w xY ww)a4  
        Create a webhook for your organization.

        Parameters
        ----------
        url : str
            URL of webhook

        actions : typing.Optional[typing.Sequence[ActionsEnum]]

        headers : typing.Optional[typing.Any]
            Key Value Json of headers

        is_active : typing.Optional[bool]
            If value is False the webhook is disabled

        project : typing.Optional[int]

        send_for_all_actions : typing.Optional[bool]
            If value is False - used only for actions from WebhookAction

        send_payload : typing.Optional[bool]
            If value is False send only action

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

        Returns
        -------
        AsyncHttpResponse[Webhook]

        r$   rI   rJ   rK   rL   rM   Nr)   r*   r+   r.   r1   )r   r5   r6   rO   r2   r7   r8   r   r   r:   r   r   r   r;   r3   r<   rP   s               r   rQ   zAsyncRawWebhooksClient.creater  s     X ..;;CC""&"(< ,  2 ,! D 
 
	$	ti++1c1"% ) 0 ))%HH&^^-N 9#8#8$yGXGXBY`noo?
:  	ty'<'<d9K\K\F]dmdrdrss	ts5   =D C D AC  D !C 1,D ?DD rR   rS   c                (  K   | j                   j                  j                  ddd|i|       d{   }	 d|j                  cxk  rdk  rGn nDt	        j
                  t        t        t        |j                                     }t        ||	      S |j                         }t        |j                  t        |j                        |
      7 # t        $ r6 t        |j                  t        |j                        |j                  
      w xY ww)a  
        Get descriptions of all available webhook actions to set up webhooks.

        Parameters
        ----------
        organization_only : typing.Optional[bool]
            organization-only or not

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

        Returns
        -------
        AsyncHttpResponse[InfoWebhooksResponse]
            Object with webhook action descriptions.
        rU   r%   rV   r&   Nr)   r*   r+   r.   r1   )r   r5   r6   r2   r7   r8   r   r   r:   r   r   r   r;   r3   r<   rW   s         r   rX   zAsyncRawWebhooksClient.info  s     , ..;;CC #%6 , D 
 
		ti++1c1("2 ) 0 ))%HH&^^-N 9#8#8$yGXGXBY`noo+
&  	ty'<'<d9K\K\F]dmdrdrss	ts3   /DCDAC DC #,D?DDrY   rZ   c                <  K   | j                   j                  j                  dt        |       dd|       d{   }	 d|j                  cxk  rdk  rGn nDt        j                  t        t        t        |j                                     }t        ||	      S |j                         }t        |j                  t        |j                        |
      7 # t        $ r6 t        |j                  t        |j                        |j                  
      w xY ww)z
        Parameters
        ----------
        id : int

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

        Returns
        -------
        AsyncHttpResponse[Webhook]

        r$   r\   r%   r]   Nr)   r*   r+   r.   r1   )r   r5   r6   r
   r2   r7   r8   r   r   r:   r   r   r   r;   r3   r<   r^   s         r   r_   zAsyncRawWebhooksClient.get  s      ..;;CC,R013+ D 
 
	
	ti++1c1"% ) 0 ))%HH&^^-N 9#8#8$yGXGXBY`noo%
   	ty'<'<d9K\K\F]dmdrdrss	ts4   9DCDAC DC -,D?DDc                  K   | j                   j                  j                  dt        |       dd|       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)
z
        Parameters
        ----------
        id : int

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

        Returns
        -------
        AsyncHttpResponse[None]
        r$   r\   ra   r]   Nr)   r*   r.   r1   )r   r5   r6   r
   r2   r   r:   r   r   r;   r3   r<   rb   s        r   rc   zAsyncRawWebhooksClient.delete  s      ..;;CC,R013+ D 
 
	
	ti++1c1()$GG&^^-N 9#8#8$yGXGXBY`noo
  	ty'<'<d9K\K\F]dmdrdrss	ts3   9C%B!C%$B# %C%&B# 6,C%#?C""C%rd   c                \  K   | j                   j                  j                  dt        |       dd||||||dddi|t               d{   }		 d	|	j
                  cxk  rd
k  rGn nDt        j                  t        t        t        |	j                                     }
t        |	|
      S |	j                         }t        |	j
                  t        |	j                        |      7 # t        $ r6 t        |	j
                  t        |	j                        |	j                         w xY ww)a  
        Parameters
        ----------
        id : int

        actions : typing.Optional[typing.Sequence[ActionsEnum]]

        headers : typing.Optional[typing.Any]
            Key Value Json of headers

        is_active : typing.Optional[bool]
            If value is False the webhook is disabled

        send_for_all_actions : typing.Optional[bool]
            If value is False - used only for actions from WebhookAction

        send_payload : typing.Optional[bool]
            If value is False send only action

        url : typing.Optional[str]
            URL of webhook

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

        Returns
        -------
        AsyncHttpResponse[WebhookSerializerForUpdate]

        r$   r\   rf   rg   rK   rL   rM   Nr)   r*   r+   r.   r1   )r   r5   r6   r
   rO   r2   r7   r8   r   r   r:   r   r   r   r;   r3   r<   rh   s               r   ri   zAsyncRawWebhooksClient.update,  s-    T ..;;CC,R013""&(< ,  2 , D 
 
	"	ti++1c1."8 ) 0 ))%HH&^^-N 9#8#8$yGXGXBY`noo=
8  	ty'<'<d9K\K\F]dmdrdrss	ts7   A	D,C(D,AC* ,D,-C* =,D,*?D))D,)rj   rk   rl   r   r   r7   rm   rn   r   r   r9   r   rA   rO   ro   r   rp   rq   rr   rQ   r   rX   r_   rc   r   ri   rs   r   r   ru   ru   D  s   .*< . 26jn(p //#.(pHNXfHg(p	6;;w/	0(p\ BF/3+/(,6:.2;?Kp Kp !=>	Kp
 ,Kp ??4(Kp %Kp %ood3Kp ood+Kp  8Kp 
7	#Kp` 48;?	+p "??40+p  8	+p
 
/	0+p\ NR"p"p+1??>+J"p	7	#"pJ NRpp+1??>+Jp	4	 p@ BF/3+/6:.2$(;?HpHp !=>	Hp
 ,Hp ??4(Hp %ood3Hp ood+Hp __S!Hp  8Hp 
5	6Hpr   ru   )r7   json.decoderr   core.api_errorr   core.client_wrapperr   r   core.http_responser   r	   core.jsonable_encoderr
   core.request_optionsr   core.unchecked_base_modelr   types.actions_enumr   types.webhookr   #types.webhook_serializer_for_updater   types.info_webhooks_responser   r8   rp   rO   r   ru   rs   r   r   <module>r      s`     ( % G @ 4 1 6 , # L > v{{6::s#lp lp^	pp ppr   