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

Documentation: http://developer.mailchimp.com/documentation/mailchimp/reference/ecommerce/stores/customers/
Schema: https://api.mailchimp.com/schema/3.0/Ecommerce/Stores/Customers/Instance.json
    )unicode_literals)BaseApi)check_emailc                       sR   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	dd Z
  ZS )StoreCustomersz
    Add Customers to your Store to track their orders and to view E-Commerce
    Data for your MailChimp lists and campaigns. Each Customer is connected to
    a MailChimp list member, so adding a Customer can also add or update a
    list member.
    c                    s,   t t| j|i | d| _d| _d| _dS )z)
        Initialize the endpoint
        zecommerce/storesN)superr   __init__endpointstore_idcustomer_id)selfargskwargs	__class__ Y/var/www/ideatree/venv/lib/python3.10/site-packages/mailchimp3/entities/storecustomers.pyr      s   
zStoreCustomers.__init__c                 C   s   || _ d|vrtdd|vrtdt|d  d|vr!td|d dvr+td| jj| |d	|d
}|durB|d | _|S d| _|S )aX  
        Add a new customer 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*,
            "email_address": string*,
            "opt_in_status": boolean*
        }
        id"The store customer must have an idemail_addressz-The store customer must have an email_addressopt_in_status-The store customer must have an opt_in_statusTF'The opt_in_status must be True or False	customersurldataN)r	   KeyErrorr   	TypeError
_mc_client_post_build_pathr
   )r   r	   r   responser   r   r   create   s    
zStoreCustomers.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 customers.

        :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
        queryparams['email_address'] = string
        Nr   r   r   )r	   r
   _iterater!   r   _get)r   r	   get_allqueryparamsr   r   r   all?   s
   zStoreCustomers.allc                 K   s,   || _ || _| jjdd| |d|i|S )a}  
        Get information about a specific customer.

        :param store_id: The store id.
        :type store_id: :py:class:`str`
        :param customer_id: The id for the customer of a store.
        :type customer_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   getV   s    zStoreCustomers.getc                 C   s&   || _ || _| jj| |d||dS )a5  
        Update a customer.

        :param store_id: The store id.
        :type store_id: :py:class:`str`
        :param customer_id: The id for the customer of a store.
        :type customer_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   updateg   s   zStoreCustomers.updatec                 C   sv   || _ || _d|vrtdd|vrtdt|d  d|vr$td|d dvr.td| jj| |d	||d
S )a  
        Add or update a customer.

        :param store_id: The store id.
        :type store_id: :py:class:`str`
        :param customer_id: The id for the customer of a store.
        :type customer_id: :py:class:`str`
        :param data: The request body parameters
        :type data: :py:class:`dict`
        data = {
            "id": string*,
            "email_address": string*,
            "opt_in_status": boolean
        }
        r   r   r   z.Each store customer must have an email_addressr   r   r   r   r   r   )r	   r
   r   r   r   r   _putr!   r+   r   r   r   create_or_updatew   s   zStoreCustomers.create_or_updatec                 C   s$   || _ || _| jj| |d|dS )z
        Delete a customer from a store.

        :param store_id: The store id.
        :type store_id: :py:class:`str`
        :param customer_id: The id for the customer of a store.
        :type customer_id: :py:class:`str`
        r   )r   )r	   r
   r   _deleter!   )r   r	   r
   r   r   r   delete   s   	zStoreCustomers.delete)F)__name__
__module____qualname____doc__r   r#   r(   r)   r,   r.   r0   __classcell__r   r   r   r   r      s    

 r   N)r4   
__future__r   mailchimp3.baseapir   mailchimp3.helpersr   r   r   r   r   r   <module>   s
   