o
    ÚtBh^(  ã                   @   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                       sP   e Zd ZdZd‡ fdd„	Z		ddd„Zdd„ Zd	d
„ Zdd„ Zdd„ Z	‡  Z
S )ÚCustomerGroupsApiz3A Controller to access Endpoints in the square API.Nc                    s   t t| ƒ ||¡ d S ©N)Úsuperr   Ú__init__)ÚselfÚconfigÚ	call_back©Ú	__class__© úu/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/square/api/customer_groups_api.pyr	      s   zCustomerGroupsApi.__init__c                 C   s¢   d}| j  ¡ }||7 }||dœ}t ||¡}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/customers/groups.

        Retrieves the list of customer groups of a business.

        Args:
            cursor (string, optional): A pagination cursor returned by a
                previous call to this endpoint. Provide this cursor to
                retrieve the next set of results for your original query.  For
                more information, see
                [Pagination](https://developer.squareup.com/docs/working-with-a
                pis/pagination).
            limit (int, optional): The maximum number of results to return in
                a single page. This limit is advisory. The response might
                contain more or fewer results. The limit is ignored if it is
                less than 1 or greater than 50. The default value is 50.  For
                more information, see
                [Pagination](https://developer.squareup.com/docs/working-with-a
                pis/pagination).

        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/customers/groups)ÚcursorÚlimitÚ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   Ú	_url_pathÚ_query_builderÚ_query_parametersÚ
_query_urlÚ_headersÚ_requestÚ	_responseÚdecodedÚ_errorsÚ_resultr   r   r   Úlist_customer_groups   s,   #
þþ
ÿ
z&CustomerGroupsApi.list_customer_groupsc                 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 )a=  Does a POST request to /v2/customers/groups.

        Creates a new customer group for a business.
        The request must include the `name` value of the group.

        Args:
            body (CreateCustomerGroupRequest): 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-   r.   r/   r   r   r   Úcreate_customer_groupR   s    

þ
z'CustomerGroupsApi.create_customer_groupc                 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 DELETE request to /v2/customers/groups/{group_id}.

        Deletes a customer group as identified by the `group_id` value.

        Args:
            group_id (string): The ID of the customer group to delete.

        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/customers/groups/{group_id}Úgroup_idT©ÚvalueÚencoder   r   r   r   Nr   )r   Ú#append_url_with_template_parametersr   r   r   r   Údeleter   r    r!   r"   r#   r$   r%   r   r   ©r
   r8   r&   r'   r)   r*   r+   r,   r-   r.   r/   r   r   r   Údelete_customer_groupƒ   s$   
ÿ

ÿ
z'CustomerGroupsApi.delete_customer_groupc                 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/customers/groups/{group_id}.

        Retrieves a specific customer group as identified by the `group_id`
        value.

        Args:
            group_id (string): The ID of the customer group to retrieve.

        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.

        r7   r8   Tr9   r   r   r   r   Nr   )r   r<   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r   r>   r   r   r   Úretrieve_customer_group³   s$   
ÿ

ÿ
z)CustomerGroupsApi.retrieve_customer_groupc                 C   s¬   d}t  |d|ddœi¡}| j ¡ }||7 }t  |¡}dddœ}| jjj||t  |¡d}t 	| j|¡ |  
|¡}t  |j¡}	t|	ƒtu rK|	 d¡}
nd	}
t||	|
d
}|S )aa  Does a PUT request to /v2/customers/groups/{group_id}.

        Updates a customer group as identified by the `group_id` value.

        Args:
            group_id (string): The ID of the customer group to update.
            body (UpdateCustomerGroupRequest): 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.

        r7   r8   Tr9   r   r1   r2   r   Nr   )r   r<   r   r   r   r   Úputr5   r   r    r!   r"   r#   r$   r%   r   r   )r
   r8   r   r&   r'   r)   r*   r+   r,   r-   r.   r/   r   r   r   Úupdate_customer_groupä   s&   
ÿ

þ
z'CustomerGroupsApi.update_customer_groupr   )NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r	   r0   r6   r?   r@   rB   Ú__classcell__r   r   r   r   r   	   s    
þB101r   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
   