# coding: utf-8

"""
    Onshape REST API

    The Onshape REST API consumed by all clients.  # noqa: E501

    OpenAPI spec version: 1.96
    Contact: api-support@onshape.zendesk.com
    Generated by: https://openapi-generator.tech
"""


from __future__ import absolute_import

import re  # noqa: F401

# python 2 and python 3 compatibility library
import six

from onshape_client.api_client import ApiClient


class AccountsApi(object):
    """NOTE: This class is auto generated by OpenAPI Generator
    Ref: https://openapi-generator.tech

    Do not edit the class manually.
    """

    def __init__(self, api_client=None):
        if api_client is None:
            api_client = ApiClient()
        self.api_client = api_client

    def cancel_purchase_new(self, aid, pid, **kwargs):  # noqa: E501
        """Cancel Recurring Subscription  # noqa: E501

        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.cancel_purchase_new(aid, pid, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str aid: (required)
        :param str pid: (required)
        :param bool cancel_immediately:
        :return: None
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('async_req'):
            return self.cancel_purchase_new_with_http_info(aid, pid, **kwargs)  # noqa: E501
        else:
            (data) = self.cancel_purchase_new_with_http_info(aid, pid, **kwargs)  # noqa: E501
            return data

    def cancel_purchase_new_with_http_info(self, aid, pid, **kwargs):  # noqa: E501
        """Cancel Recurring Subscription  # noqa: E501

        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.cancel_purchase_new_with_http_info(aid, pid, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str aid: (required)
        :param str pid: (required)
        :param bool cancel_immediately:
        :return: None
                 If the method is called asynchronously,
                 returns the request thread.
        """

        local_var_params = locals()

        all_params = ['aid', 'pid', 'cancel_immediately']  # noqa: E501
        all_params.append('async_req')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

        for key, val in six.iteritems(local_var_params['kwargs']):
            if key not in all_params:
                raise TypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method cancel_purchase_new" % key
                )
            local_var_params[key] = val
        del local_var_params['kwargs']
        # verify the required parameter 'aid' is set
        if ('aid' not in local_var_params or
                local_var_params['aid'] is None):
            raise ValueError("Missing the required parameter `aid` when calling `cancel_purchase_new`")  # noqa: E501
        # verify the required parameter 'pid' is set
        if ('pid' not in local_var_params or
                local_var_params['pid'] is None):
            raise ValueError("Missing the required parameter `pid` when calling `cancel_purchase_new`")  # noqa: E501

        collection_formats = {}

        path_params = {}
        if 'aid' in local_var_params:
            path_params['aid'] = local_var_params['aid']  # noqa: E501
        if 'pid' in local_var_params:
            path_params['pid'] = local_var_params['pid']  # noqa: E501

        query_params = []
        if 'cancel_immediately' in local_var_params:
            query_params.append(('cancelImmediately', local_var_params['cancel_immediately']))  # noqa: E501

        header_params = {}

        form_params = []
        local_var_files = {}

        body_params = None
        # HTTP header `Accept`
        header_params['Accept'] = self.api_client.select_header_accept(
            ['application/vnd.onshape.v1+json;charset=UTF-8; qs=0.1', 'application/json;charset=UTF-8; qs=0.9'])  # noqa: E501

        # Authentication setting
        auth_settings = ['OAuth2']  # noqa: E501

        return self.api_client.call_api(
            '/api/accounts/{aid}/purchases/{pid}', 'DELETE',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type=None,  # noqa: E501
            auth_settings=auth_settings,
            async_req=local_var_params.get('async_req'),
            _return_http_data_only=local_var_params.get('_return_http_data_only'),  # noqa: E501
            _preload_content=local_var_params.get('_preload_content', True),
            _request_timeout=local_var_params.get('_request_timeout'),
            collection_formats=collection_formats)

    def consume_purchase(self, pid, **kwargs):  # noqa: E501
        """Mark Purchase Consumed For User  # noqa: E501

        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.consume_purchase(pid, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str pid: (required)
        :param BTPurchaseUserParams bt_purchase_user_params:
        :return: BTPurchaseInfo
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('async_req'):
            return self.consume_purchase_with_http_info(pid, **kwargs)  # noqa: E501
        else:
            (data) = self.consume_purchase_with_http_info(pid, **kwargs)  # noqa: E501
            return data

    def consume_purchase_with_http_info(self, pid, **kwargs):  # noqa: E501
        """Mark Purchase Consumed For User  # noqa: E501

        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.consume_purchase_with_http_info(pid, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str pid: (required)
        :param BTPurchaseUserParams bt_purchase_user_params:
        :return: BTPurchaseInfo
                 If the method is called asynchronously,
                 returns the request thread.
        """

        local_var_params = locals()

        all_params = ['pid', 'bt_purchase_user_params']  # noqa: E501
        all_params.append('async_req')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

        for key, val in six.iteritems(local_var_params['kwargs']):
            if key not in all_params:
                raise TypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method consume_purchase" % key
                )
            local_var_params[key] = val
        del local_var_params['kwargs']
        # verify the required parameter 'pid' is set
        if ('pid' not in local_var_params or
                local_var_params['pid'] is None):
            raise ValueError("Missing the required parameter `pid` when calling `consume_purchase`")  # noqa: E501

        collection_formats = {}

        path_params = {}
        if 'pid' in local_var_params:
            path_params['pid'] = local_var_params['pid']  # noqa: E501

        query_params = []

        header_params = {}

        form_params = []
        local_var_files = {}

        body_params = None
        if 'bt_purchase_user_params' in local_var_params:
            body_params = local_var_params['bt_purchase_user_params']
        # HTTP header `Accept`
        header_params['Accept'] = self.api_client.select_header_accept(
            ['application/vnd.onshape.v1+json;charset=UTF-8; qs=0.1', 'application/json;charset=UTF-8; qs=0.9'])  # noqa: E501

        # HTTP header `Content-Type`
        header_params['Content-Type'] = self.api_client.select_header_content_type(  # noqa: E501
            ['application/json;charset=UTF-8'])  # noqa: E501

        # Authentication setting
        auth_settings = ['OAuth2']  # noqa: E501

        return self.api_client.call_api(
            '/api/accounts/purchases/{pid}/consume', 'POST',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='BTPurchaseInfo',  # noqa: E501
            auth_settings=auth_settings,
            async_req=local_var_params.get('async_req'),
            _return_http_data_only=local_var_params.get('_return_http_data_only'),  # noqa: E501
            _preload_content=local_var_params.get('_preload_content', True),
            _request_timeout=local_var_params.get('_request_timeout'),
            collection_formats=collection_formats)

    def get_plan_purchases(self, plan_id, **kwargs):  # noqa: E501
        """Get Plan Purchases  # noqa: E501

        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.get_plan_purchases(plan_id, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str plan_id: (required)
        :param int offset:
        :param int limit:
        :return: BTListResponseBTPurchaseInfo
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('async_req'):
            return self.get_plan_purchases_with_http_info(plan_id, **kwargs)  # noqa: E501
        else:
            (data) = self.get_plan_purchases_with_http_info(plan_id, **kwargs)  # noqa: E501
            return data

    def get_plan_purchases_with_http_info(self, plan_id, **kwargs):  # noqa: E501
        """Get Plan Purchases  # noqa: E501

        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.get_plan_purchases_with_http_info(plan_id, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str plan_id: (required)
        :param int offset:
        :param int limit:
        :return: BTListResponseBTPurchaseInfo
                 If the method is called asynchronously,
                 returns the request thread.
        """

        local_var_params = locals()

        all_params = ['plan_id', 'offset', 'limit']  # noqa: E501
        all_params.append('async_req')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

        for key, val in six.iteritems(local_var_params['kwargs']):
            if key not in all_params:
                raise TypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method get_plan_purchases" % key
                )
            local_var_params[key] = val
        del local_var_params['kwargs']
        # verify the required parameter 'plan_id' is set
        if ('plan_id' not in local_var_params or
                local_var_params['plan_id'] is None):
            raise ValueError("Missing the required parameter `plan_id` when calling `get_plan_purchases`")  # noqa: E501

        collection_formats = {}

        path_params = {}
        if 'plan_id' in local_var_params:
            path_params['planId'] = local_var_params['plan_id']  # noqa: E501

        query_params = []
        if 'offset' in local_var_params:
            query_params.append(('offset', local_var_params['offset']))  # noqa: E501
        if 'limit' in local_var_params:
            query_params.append(('limit', local_var_params['limit']))  # noqa: E501

        header_params = {}

        form_params = []
        local_var_files = {}

        body_params = None
        # HTTP header `Accept`
        header_params['Accept'] = self.api_client.select_header_accept(
            ['application/vnd.onshape.v1+json;charset=UTF-8; qs=0.1', 'application/json;charset=UTF-8; qs=0.9'])  # noqa: E501

        # Authentication setting
        auth_settings = []  # noqa: E501

        return self.api_client.call_api(
            '/api/accounts/plans/{planId}/purchases', 'GET',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='BTListResponseBTPurchaseInfo',  # noqa: E501
            auth_settings=auth_settings,
            async_req=local_var_params.get('async_req'),
            _return_http_data_only=local_var_params.get('_return_http_data_only'),  # noqa: E501
            _preload_content=local_var_params.get('_preload_content', True),
            _request_timeout=local_var_params.get('_request_timeout'),
            collection_formats=collection_formats)

    def get_purchases(self, **kwargs):  # noqa: E501
        """Get User's Appstore Purchases.  # noqa: E501

        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.get_purchases(async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param bool all:
        :param bool own_purchase_only:
        :return: list[BTPurchaseInfo]
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('async_req'):
            return self.get_purchases_with_http_info(**kwargs)  # noqa: E501
        else:
            (data) = self.get_purchases_with_http_info(**kwargs)  # noqa: E501
            return data

    def get_purchases_with_http_info(self, **kwargs):  # noqa: E501
        """Get User's Appstore Purchases.  # noqa: E501

        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.get_purchases_with_http_info(async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param bool all:
        :param bool own_purchase_only:
        :return: list[BTPurchaseInfo]
                 If the method is called asynchronously,
                 returns the request thread.
        """

        local_var_params = locals()

        all_params = ['all', 'own_purchase_only']  # noqa: E501
        all_params.append('async_req')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

        for key, val in six.iteritems(local_var_params['kwargs']):
            if key not in all_params:
                raise TypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method get_purchases" % key
                )
            local_var_params[key] = val
        del local_var_params['kwargs']

        collection_formats = {}

        path_params = {}

        query_params = []
        if 'all' in local_var_params:
            query_params.append(('all', local_var_params['all']))  # noqa: E501
        if 'own_purchase_only' in local_var_params:
            query_params.append(('ownPurchaseOnly', local_var_params['own_purchase_only']))  # noqa: E501

        header_params = {}

        form_params = []
        local_var_files = {}

        body_params = None
        # HTTP header `Accept`
        header_params['Accept'] = self.api_client.select_header_accept(
            ['application/vnd.onshape.v1+json;charset=UTF-8; qs=0.1', 'application/json;charset=UTF-8; qs=0.9'])  # noqa: E501

        # Authentication setting
        auth_settings = []  # noqa: E501

        return self.api_client.call_api(
            '/api/accounts/purchases', 'GET',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='list[BTPurchaseInfo]',  # noqa: E501
            auth_settings=auth_settings,
            async_req=local_var_params.get('async_req'),
            _return_http_data_only=local_var_params.get('_return_http_data_only'),  # noqa: E501
            _preload_content=local_var_params.get('_preload_content', True),
            _request_timeout=local_var_params.get('_request_timeout'),
            collection_formats=collection_formats)
