o
    tBhC                     @   sP   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	 G dd deZ
dS )	    )	APIHelper)ApiResponse)FileWrapper)BaseApi)OAuth2c                       s   e Zd ZdZd  fdd	Zdd Zdd Zd	d
 Z		d!ddZdd Z				d"ddZ
dd Zdd Z		d#ddZdd Zdd Zdd Zdd Z  ZS )$
CatalogApiz3A 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/catalog_api.pyr
      s   zCatalogApi.__init__c                 C      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 )aQ  Does a POST request to /v2/catalog/batch-delete.

        Deletes a set of [CatalogItem]($m/CatalogItem)s based on the
        provided list of target IDs and returns a set of successfully deleted
        IDs in
        the response. Deletion is a cascading event such that all children of
        the
        targeted object are also deleted. For example, deleting a CatalogItem
        will
        also delete all of its
        [CatalogItemVariation]($m/CatalogItemVariation)
        children.
        `BatchDeleteCatalogObjects` succeeds even if only a portion of the
        targeted
        IDs can be deleted. The response will only include IDs that were
        actually deleted.

        Args:
            body (BatchDeleteCatalogObjectsRequest): 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.

        z/v2/catalog/batch-deleteapplication/jsonacceptzContent-Typeheaders
parameterserrorsNbodyr   r   get_base_urir   	clean_urlhttp_clientpostjson_serializer   applyexecute_requestjson_deserializetexttypedictgetr   r   r   	_url_path_query_builder
_query_url_headers_request	_responsedecoded_errors_resultr   r   r   batch_delete_catalog_objects   s    %


z'CatalogApi.batch_delete_catalog_objectsc                 C   r   )a  Does a POST request to /v2/catalog/batch-retrieve.

        Returns a set of objects based on the provided ID.
        Each [CatalogItem]($m/CatalogItem) returned in the set includes all of
        its
        child information including: all of its
        [CatalogItemVariation]($m/CatalogItemVariation) objects, references
        to
        its [CatalogModifierList]($m/CatalogModifierList) objects, and the ids
        of
        any [CatalogTax]($m/CatalogTax) objects that apply to it.

        Args:
            body (BatchRetrieveCatalogObjectsRequest): 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.

        z/v2/catalog/batch-retriever   r   r   r   Nr   r   r)   r   r   r   batch_retrieve_catalog_objectsN   s     


z)CatalogApi.batch_retrieve_catalog_objectsc                 C   r   )a  Does a POST request to /v2/catalog/batch-upsert.

        Creates or updates up to 10,000 target objects based on the provided
        list of objects. The target objects are grouped into batches and each
        batch is
        inserted/updated in an all-or-nothing manner. If an object within a
        batch is
        malformed in some way, or violates a database constraint, the entire
        batch
        containing that item will be disregarded. However, other batches in
        the same
        request may still succeed. Each batch may contain up to 1,000 objects,
        and
        batches will be processed in order as long as the total object count
        for the
        request (items, variations, modifier lists, discounts, and taxes) is
        no more
        than 10,000.

        Args:
            body (BatchUpsertCatalogObjectsRequest): 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.

        z/v2/catalog/batch-upsertr   r   r   r   Nr   r   r)   r   r   r   batch_upsert_catalog_objects   s    '


z'CatalogApi.batch_upsert_catalog_objectsc                 C   s   d}| j  }||7 }t|}t|tr|j}|j}n|}d}dt|df|j	||fd}ddi}	| j j
j||	|d}
t| j |
 | |
}t|j}t|tu r[|d	}nd}t|||d
}|S )a  Does a POST request to /v2/catalog/images.

        Uploads an image file to be represented by a
        [CatalogImage]($m/CatalogImage) object linked to an existing
        [CatalogObject]($m/CatalogObject) instance. A call to this endpoint
        can upload an image, link an image to
        a catalog object, or do both.
        This `CreateCatalogImage` endpoint accepts HTTP multipart/form-data
        requests with a JSON part and an image file part in
        JPEG, PJPEG, PNG, or GIF format. The maximum file size is 15MB.

        Args:
            request (CreateCatalogImageRequest, optional): TODO: type
                description here.
            image_file (typing.BinaryIO, optional): TODO: type description
                here.

        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/catalog/imagesz
image/jpegNzapplication/json; charset=utf-8)request
image_filer   r   )r   filesr   r   )r   r   r   r   
isinstancer   file_streamcontent_typer!   namer   r    r   r"   r#   r$   r%   r&   r'   r(   r   )r   r6   r7   r*   r+   r,   image_file_wrapperimage_file_content_type_filesr-   r.   r/   r0   r1   r2   r   r   r   create_catalog_image   s.   !




zCatalogApi.create_catalog_imagec           
      C   s   d}| j  }||7 }t|}ddi}| j jj||d}t| j | | |}t	|j
}t|tu r;|d}nd}t|||d}	|	S )a  Does a GET request to /v2/catalog/info.

        Retrieves information about the Square Catalog API, such as batch
        size
        limits that can be used by the `BatchUpsertCatalogObjects` endpoint.

        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/catalog/infor   r   r   r   Nr   )r   r   r   r   r   r(   r   r"   r#   r$   r%   r&   r'   r   )
r   r*   r+   r,   r-   r.   r/   r0   r1   r2   r   r   r   catalog_info
  s   


zCatalogApi.catalog_infoc                 C   s   d}| j  }||7 }|||d}t||}t|}ddi}| j jj||d}	t| j |	 | 	|	}
t
|
j}t|tu rG|d}nd}t|
||d}|S )	a	  Does a GET request to /v2/catalog/list.

        Returns a list of [CatalogObject]($m/CatalogObject)s that includes
        all objects of a set of desired types (for example, all
        [CatalogItem]($m/CatalogItem)
        and [CatalogTax]($m/CatalogTax) objects) in the catalog. The `types`
        parameter
        is specified as a comma-separated list of valid
        [CatalogObject]($m/CatalogObject) types:
        `ITEM`, `ITEM_VARIATION`, `MODIFIER`, `MODIFIER_LIST`, `CATEGORY`,
        `DISCOUNT`, `TAX`, `IMAGE`.
        __Important:__ ListCatalog does not return deleted catalog items. To
        retrieve
        deleted catalog items, use
        [SearchCatalogObjects]($e/Catalog/SearchCatalogObjects)
        and set the `include_deleted_objects` attribute value to `true`.

        Args:
            cursor (string, optional): The pagination cursor returned in the
                previous response. Leave unset for an initial request. The
                page size is currently set to be 100. See
                [Pagination](https://developer.squareup.com/docs/basics/api101/
                pagination) for more information.
            types (string, optional): An optional case-insensitive,
                comma-separated list of object types to retrieve.  The valid
                values are defined in the
                [CatalogObjectType]($m/CatalogObjectType) enum, including
                `ITEM`, `ITEM_VARIATION`, `CATEGORY`, `DISCOUNT`, `TAX`,
                `MODIFIER`, `MODIFIER_LIST`, or `IMAGE`.  If this is
                unspecified, the operation returns objects of all the types at
                the version of the Square API used to make the request.
            catalog_version (long|int, optional): The specific version of the
                catalog objects to be included in the response.  This allows
                you to retrieve historical versions of objects. The specified
                version value is matched against the
                [CatalogObject]($m/CatalogObject)s' `version` attribute.

        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/catalog/list)cursortypescatalog_versionr   r   rA   r   Nr   )r   r   r    append_url_with_query_parametersr   r   r(   r   r"   r#   r$   r%   r&   r'   r   )r   rC   rD   rE   r*   r+   _query_parametersr,   r-   r.   r/   r0   r1   r2   r   r   r   list_catalog5  s.   6


zCatalogApi.list_catalogc                 C   r   )a  Does a POST request to /v2/catalog/object.

        Creates or updates the target [CatalogObject]($m/CatalogObject).

        Args:
            body (UpsertCatalogObjectRequest): 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.

        z/v2/catalog/objectr   r   r   r   Nr   r   r)   r   r   r   upsert_catalog_object  s    


z CatalogApi.upsert_catalog_objectc                 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/catalog/object/{object_id}.

        Deletes a single [CatalogObject]($m/CatalogObject) based on the
        provided ID and returns the set of successfully deleted IDs in the
        response.
        Deletion is a cascading event such that all children of the targeted
        object
        are also deleted. For example, deleting a
        [CatalogItem]($m/CatalogItem)
        will also delete all of its
        [CatalogItemVariation]($m/CatalogItemVariation) children.

        Args:
            object_id (string): The ID of the catalog object to be deleted.
                When an object is deleted, other objects in the graph that
                depend on that object will be deleted as well (for example,
                deleting a catalog item will delete its catalog item
                variations).

        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/catalog/object/{object_id}	object_idTvalueencoder   r   rA   r   Nr   )r   #append_url_with_template_parametersr   r   r   r   deleter   r"   r#   r$   r%   r&   r'   r(   r   )r   rK   r*   r+   r,   r-   r.   r/   r0   r1   r2   r   r   r   delete_catalog_object  s$   "



z CatalogApi.delete_catalog_objectFc                 C   s   d}t |d|ddi}| j }||7 }||d}t ||}t |}ddi}| jjj||d}	t	| j|	 | 
|	}
t |
j}t|tu rQ|d	}nd
}t|
||d}|S )a  Does a GET request to /v2/catalog/object/{object_id}.

        Returns a single [CatalogItem]($m/CatalogItem) as a
        [CatalogObject]($m/CatalogObject) based on the provided ID. The
        returned
        object includes all of the relevant [CatalogItem]($m/CatalogItem)
        information including:
        [CatalogItemVariation]($m/CatalogItemVariation)
        children, references to its
        [CatalogModifierList]($m/CatalogModifierList) objects, and the ids of
        any [CatalogTax]($m/CatalogTax) objects that apply to it.

        Args:
            object_id (string): The object ID of any type of catalog objects
                to be retrieved.
            include_related_objects (bool, optional): If `true`, the response
                will include additional objects that are related to the
                requested object, as follows:  If the `object` field of the
                response contains a `CatalogItem`, its associated
                `CatalogCategory`, `CatalogTax`, `CatalogImage` and
                `CatalogModifierList` objects will be returned in the
                `related_objects` field of the response. If the `object` field
                of the response contains a `CatalogItemVariation`, its parent
                `CatalogItem` will be returned in the `related_objects` field
                of the response.  Default value: `false`
            catalog_version (long|int, optional): Requests objects as of a
                specific version of the catalog. This allows you to retrieve
                historical versions of objects. The value to retrieve a
                specific version of an object can be found in the version
                field of [CatalogObject]($m/CatalogObject)s.

        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.

        rJ   rK   TrL   )include_related_objectsrE   r   r   rA   r   Nr   )r   rO   r   r   rF   r   r   r(   r   r"   r#   r$   r%   r&   r'   r   )r   rK   rR   rE   r*   r+   rG   r,   r-   r.   r/   r0   r1   r2   r   r   r   retrieve_catalog_object  s2   0



z"CatalogApi.retrieve_catalog_objectc                 C   r   )a  Does a POST request to /v2/catalog/search.

        Searches for [CatalogObject]($m/CatalogObject) of any type by matching
        supported search attribute values,
        excluding custom attribute values on items or item variations, against
        one or more of the specified query filters.
        This (`SearchCatalogObjects`) endpoint differs from the
        [SearchCatalogItems]($e/Catalog/SearchCatalogItems)
        endpoint in the following aspects:
        - `SearchCatalogItems` can only search for items or item variations,
        whereas `SearchCatalogObjects` can search for any type of catalog
        objects.
        - `SearchCatalogItems` supports the custom attribute query filters to
        return items or item variations that contain custom attribute values,
        where `SearchCatalogObjects` does not.
        - `SearchCatalogItems` does not support the `include_deleted_objects`
        filter to search for deleted items or item variations, whereas
        `SearchCatalogObjects` does.
        - The both endpoints have different call conventions, including the
        query filter formats.

        Args:
            body (SearchCatalogObjectsRequest): 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.

        z/v2/catalog/searchr   r   r   r   Nr   r   r)   r   r   r   search_catalog_objectsI      )


z!CatalogApi.search_catalog_objectsc                 C   r   )a  Does a POST request to /v2/catalog/search-catalog-items.

        Searches for catalog items or item variations by matching supported
        search attribute values, including
        custom attribute values, against one or more of the specified query
        filters.
        This (`SearchCatalogItems`) endpoint differs from the
        [SearchCatalogObjects]($e/Catalog/SearchCatalogObjects)
        endpoint in the following aspects:
        - `SearchCatalogItems` can only search for items or item variations,
        whereas `SearchCatalogObjects` can search for any type of catalog
        objects.
        - `SearchCatalogItems` supports the custom attribute query filters to
        return items or item variations that contain custom attribute values,
        where `SearchCatalogObjects` does not.
        - `SearchCatalogItems` does not support the `include_deleted_objects`
        filter to search for deleted items or item variations, whereas
        `SearchCatalogObjects` does.
        - The both endpoints use different call conventions, including the
        query filter formats.

        Args:
            body (SearchCatalogItemsRequest): 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.

        z /v2/catalog/search-catalog-itemsr   r   r   r   Nr   r   r)   r   r   r   search_catalog_items  rU   zCatalogApi.search_catalog_itemsc                 C   r   )a  Does a POST request to /v2/catalog/update-item-modifier-lists.

        Updates the [CatalogModifierList]($m/CatalogModifierList) objects
        that apply to the targeted [CatalogItem]($m/CatalogItem) without
        having
        to perform an upsert on the entire item.

        Args:
            body (UpdateItemModifierListsRequest): 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.

        z&/v2/catalog/update-item-modifier-listsr   r   r   r   Nr   r   r)   r   r   r   update_item_modifier_lists  s    


z%CatalogApi.update_item_modifier_listsc                 C   r   )a  Does a POST request to /v2/catalog/update-item-taxes.

        Updates the [CatalogTax]($m/CatalogTax) objects that apply to the
        targeted [CatalogItem]($m/CatalogItem) without having to perform an
        upsert on the entire item.

        Args:
            body (UpdateItemTaxesRequest): 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.

        z/v2/catalog/update-item-taxesr   r   r   r   Nr   r   r)   r   r   r   update_item_taxes  s    


zCatalogApi.update_item_taxesr   )NN)NNN)FN)__name__
__module____qualname____doc__r
   r3   r4   r5   r@   rB   rH   rI   rQ   rS   rT   rV   rW   rX   __classcell__r   r   r   r   r   
   s.    =8@
E,
V0>
RAA3r   N)square.api_helperr   square.http.api_responser   square.utilities.file_wrapperr   square.api.base_apir   square.http.auth.o_auth_2r   r   r   r   r   r   <module>   s   