o
    tBhV                     @   sD   d dl mZ d dlmZ d dlmZ d dlmZ G dd deZdS )    )	APIHelper)ApiResponse)BaseApi)OAuth2c                       sD   e Zd ZdZd fdd	Z				dddZdd Zd	d
 Z  ZS )
DevicesApiz3A Controller to access Endpoints in the square API.Nc                    s   t t| || d S N)superr   __init__)selfconfig	call_back	__class__ m/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/square/api/devices_api.pyr	      s   zDevicesApi.__init__c                 C   s   d}| j  }||7 }||||d}t||}t|}ddi}	| j jj||	d}
t| j |
 | 	|
}t
|j}t|tu rH|d}nd}t|||d}|S )	a  Does a GET request to /v2/devices/codes.

        Lists all DeviceCodes associated with the merchant.

        Args:
            cursor (string, optional): A pagination cursor returned by a
                previous call to this endpoint. Provide this to retrieve the
                next set of results for your original query.  See [Paginating
                results](https://developer.squareup.com/docs/working-with-apis/
                pagination) for more information.
            location_id (string, optional): If specified, only returns
                DeviceCodes of the specified location. Returns DeviceCodes of
                all locations if empty.
            product_type (ProductType, optional): If specified, only returns
                DeviceCodes targeting the specified product type. Returns
                DeviceCodes of all product types if empty.
            status (DeviceCodeStatus, optional): If specified, returns
                DeviceCodes with the specified statuses. Returns DeviceCodes
                of status `PAIRED` and `UNPAIRED` if empty.

        Returns:
            ApiResponse: An object with the response value as well as other
                useful information such as status codes and headers. Success

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        /v2/devices/codes)cursorlocation_idproduct_typestatusacceptapplication/jsonheaderserrorsNbodyr   )r   get_base_urir    append_url_with_query_parameters	clean_urlhttp_clientgetr   applyexecute_requestjson_deserializetexttypedictr   )r
   r   r   r   r   	_url_path_query_builder_query_parameters
_query_url_headers_request	_responsedecoded_errors_resultr   r   r   list_device_codes   s0   &


zDevicesApi.list_device_codesc                 C   s   d}| j  }||7 }t|}ddd}| j jj||t|d}t| j | | 	|}t
|j}t|tu r@|d}	nd}	t|||	d}
|
S )aK  Does a POST request to /v2/devices/codes.

        Creates a DeviceCode that can be used to login to a Square Terminal
        device to enter the connected
        terminal mode.

        Args:
            body (CreateDeviceCodeRequest): An object containing the fields to
                POST for the request.  See the corresponding object definition
                for field details.

        Returns:
            ApiResponse: An object with the response value as well as other
                useful information such as status codes and headers. Success

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        r   r   )r   zContent-Type)r   
parametersr   Nr   )r   r   r   r   r    postjson_serializer   r"   r#   r$   r%   r&   r'   r!   r   )r
   r   r(   r)   r+   r,   r-   r.   r/   r0   r1   r   r   r   create_device_codeW   s    


zDevicesApi.create_device_codec                 C   s   d}t |d|ddi}| j }||7 }t |}ddi}| jjj||d}t| j| | 	|}t 
|j}t|tu rF|d}	nd	}	t|||	d
}
|
S )a~  Does a GET request to /v2/devices/codes/{id}.

        Retrieves DeviceCode with the associated ID.

        Args:
            id (string): The unique identifier for the device code.

        Returns:
            ApiResponse: An object with the response value as well as other
                useful information such as status codes and headers. Success

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        z/v2/devices/codes/{id}idT)valueencoder   r   r   r   Nr   )r   #append_url_with_template_parametersr   r   r   r    r!   r   r"   r#   r$   r%   r&   r'   r   )r
   r7   r(   r)   r+   r,   r-   r.   r/   r0   r1   r   r   r   get_device_code   s$   



zDevicesApi.get_device_coder   )NNNN)	__name__
__module____qualname____doc__r	   r2   r6   r;   __classcell__r   r   r   r   r   	   s    
G2r   N)	square.api_helperr   square.http.api_responser   square.api.base_apir   square.http.auth.o_auth_2r   r   r   r   r   r   <module>   s
   