o
    ˷e                      @   sD   d Z ddlmZ ddlZddlmZ ddlmZ G dd deZdS )z
The E-commerce Store Carts endpoint API endpoint

Documentation: http://developer.mailchimp.com/documentation/mailchimp/reference/ecommerce/stores/carts/
Schema: https://api.mailchimp.com/schema/3.0/Ecommerce/Stores/Carts/Instance.json
    )unicode_literalsN)BaseApi)StoreCartLinesc                       sJ   e Zd ZdZ fddZdd ZdddZd	d
 Zdd Zdd Z	  Z
S )
StoreCartsu   
    Use Carts to represent unfinished e-commerce transactions. This can be
    used to create an Abandoned Cart workflow, or to save a consumer’s
    shopping cart pending a successful Order.
    c                    s6   t t| j|i | d| _d| _d| _t| | _dS )z)
        Initialize the endpoint
        zecommerce/storesN)superr   __init__endpointstore_idcart_idr   lines)selfargskwargs	__class__ U/var/www/ideatree/venv/lib/python3.10/site-packages/mailchimp3/entities/storecarts.pyr      s
   zStoreCarts.__init__c                 C   s  || _ d|vrtdd|vrtdd|d vrtdd|vr%tdtd|d s1td	d
|vr9tdd|vrAtd|d D ]*}d|vrOtdd|vrWtdd|vr_tdd|vrgtdd|vrotdqE| jj| |d|d}|dur|d | _|S d| _|S )a  
        Add a new cart to a store.

        :param store_id: The store id.
        :type store_id: :py:class:`str`
        :param data: The request body parameters
        :type data: :py:class:`dict`
        data = {
            "id": string*,
            "customer": object*
            {
                "id": string*
            },
            "currency_code": string*,
            "order_total": number*,
            "lines": array*
            [
                {
                    "id": string*,
                    "product_id": string*,
                    "product_variant_id": string*,
                    "quantity": integer*,
                    "price": number*
                }
            ]
        }
        idzThe cart must have an idcustomerzThe cart must have a customerz!The cart customer must have an idcurrency_codez"The cart must have a currency_codez
^[A-Z]{3}$zAThe currency_code must be a valid 3-letter ISO 4217 currency codeorder_totalz!The cart must have an order_totalr   z)The cart must have at least one cart linezEach cart line must have an id
product_idz%Each cart line must have a product_idproduct_variant_idz-Each cart line must have a product_variant_idquantityz#Each cart line must have a quantitypricez Each cart line must have a pricecartsurldataN)	r	   KeyErrorrematch
ValueError
_mc_client_post_build_pathr
   )r   r	   r   lineresponser   r   r   create!   sB   
zStoreCarts.createFc                 K   sJ   || _ d| _|r| jdd| |di|S | jjdd| |di|S )u  
        Get information about a store’s carts.

        :param store_id: The store id.
        :type store_id: :py:class:`str`
        :param get_all: Should the query get all results
        :type get_all: :py:class:`bool`
        :param queryparams: The query string parameters
        queryparams['fields'] = []
        queryparams['exclude_fields'] = []
        queryparams['count'] = integer
        queryparams['offset'] = integer
        Nr   r   r   )r	   r
   _iterater%   r#   _get)r   r	   get_allqueryparamsr   r   r   all_   s
   zStoreCarts.allc                 K   s,   || _ || _| jjdd| |d|i|S )ab  
        Get information about a specific cart.

        :param store_id: The store id.
        :type store_id: :py:class:`str`
        :param cart_id: The id for the cart.
        :type cart_id: :py:class:`str`
        :param queryparams: The query string parameters
        queryparams['fields'] = []
        queryparams['exclude_fields'] = []
        r   r   Nr   )r	   r
   r#   r*   r%   )r   r	   r
   r,   r   r   r   getu   s    zStoreCarts.getc                 C   s&   || _ || _| jj| |d||dS )a#  
        Update a specific cart.

        :param store_id: The store id.
        :type store_id: :py:class:`str`
        :param cart_id: The id for the cart.
        :type cart_id: :py:class:`str`
        :param data: The request body parameters
        :type data: :py:class:`dict`
        r   r   )r	   r
   r#   _patchr%   )r   r	   r
   r   r   r   r   update   s   zStoreCarts.updatec                 C   s$   || _ || _| jj| |d|dS )z
        Delete a cart.

        :param store_id: The store id.
        :type store_id: :py:class:`str`
        :param cart_id: The id for the cart.
        :type cart_id: :py:class:`str`
        r   )r   )r	   r
   r#   _deleter%   )r   r	   r
   r   r   r   delete   s   	zStoreCarts.delete)F)__name__
__module____qualname____doc__r   r(   r-   r.   r0   r2   __classcell__r   r   r   r   r      s    
>r   )	r6   
__future__r   r    mailchimp3.baseapir   "mailchimp3.entities.storecartlinesr   r   r   r   r   r   <module>   s   