# coding: utf-8

"""
    Alteryx Server API V3

    No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)  # noqa: E501

    OpenAPI spec version: 3
    
    Generated by: https://github.com/swagger-api/swagger-codegen.git
"""

from __future__ import absolute_import

import re  # noqa: F401

# python 2 and python 3 compatibility library
import six

from src.server_client.api_client import ApiClient


class SubscriptionsApi(object):
    """NOTE: This class is auto generated by the swagger code generator program.

    Do not edit the class manually.
    Ref: https://github.com/swagger-api/swagger-codegen
    """

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

    def subscriptions_change_users_subscription(self, subscription_id, contract, **kwargs):  # noqa: E501
        """Change users subscription.  # noqa: E501

        Only Curators can use this API endpoint.  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.subscriptions_change_users_subscription(subscription_id, contract, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str subscription_id: Identifier for an existing subscription. (required)
        :param ChangeUsersSubscriptionContract contract: The request body structure required to change users subscription. (required)
        :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.subscriptions_change_users_subscription_with_http_info(subscription_id, contract, **kwargs)  # noqa: E501
        else:
            (data) = self.subscriptions_change_users_subscription_with_http_info(subscription_id, contract, **kwargs)  # noqa: E501
            return data

    def subscriptions_change_users_subscription_with_http_info(self, subscription_id, contract, **kwargs):  # noqa: E501
        """Change users subscription.  # noqa: E501

        Only Curators can use this API endpoint.  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.subscriptions_change_users_subscription_with_http_info(subscription_id, contract, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str subscription_id: Identifier for an existing subscription. (required)
        :param ChangeUsersSubscriptionContract contract: The request body structure required to change users subscription. (required)
        :return: None
                 If the method is called asynchronously,
                 returns the request thread.
        """

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

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

        collection_formats = {}

        path_params = {}
        if 'subscription_id' in params:
            path_params['subscriptionId'] = params['subscription_id']  # noqa: E501

        query_params = []

        header_params = {}

        form_params = []
        local_var_files = {}

        body_params = None
        if 'contract' in params:
            body_params = params['contract']
        # HTTP header `Accept`
        header_params['Accept'] = self.api_client.select_header_accept(
            ['application/json', 'text/json', 'application/xml', 'text/xml'])  # noqa: E501

        # HTTP header `Content-Type`
        header_params['Content-Type'] = self.api_client.select_header_content_type(  # noqa: E501
            ['application/json', 'text/json', 'application/xml', 'text/xml', 'application/x-www-form-urlencoded'])  # noqa: E501

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

        return self.api_client.call_api(
            '/v3/subscriptions/{subscriptionId}/users', 'PUT',
            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=params.get('async_req'),
            _return_http_data_only=params.get('_return_http_data_only'),
            _preload_content=params.get('_preload_content', True),
            _request_timeout=params.get('_request_timeout'),
            collection_formats=collection_formats)

    def subscriptions_create_subscription(self, contract, **kwargs):  # noqa: E501
        """Create new subscription.  # noqa: E501

        Only Curators can use this API endpoint.  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.subscriptions_create_subscription(contract, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param CreateSubscriptionContract contract: The request body structure required to make a new Subscription. (required)
        :return: object
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('async_req'):
            return self.subscriptions_create_subscription_with_http_info(contract, **kwargs)  # noqa: E501
        else:
            (data) = self.subscriptions_create_subscription_with_http_info(contract, **kwargs)  # noqa: E501
            return data

    def subscriptions_create_subscription_with_http_info(self, contract, **kwargs):  # noqa: E501
        """Create new subscription.  # noqa: E501

        Only Curators can use this API endpoint.  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.subscriptions_create_subscription_with_http_info(contract, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param CreateSubscriptionContract contract: The request body structure required to make a new Subscription. (required)
        :return: object
                 If the method is called asynchronously,
                 returns the request thread.
        """

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

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

        collection_formats = {}

        path_params = {}

        query_params = []

        header_params = {}

        form_params = []
        local_var_files = {}

        body_params = None
        if 'contract' in params:
            body_params = params['contract']
        # HTTP header `Accept`
        header_params['Accept'] = self.api_client.select_header_accept(
            ['application/json', 'text/json', 'application/xml', 'text/xml'])  # noqa: E501

        # HTTP header `Content-Type`
        header_params['Content-Type'] = self.api_client.select_header_content_type(  # noqa: E501
            ['application/json', 'text/json', 'application/xml', 'text/xml', 'application/x-www-form-urlencoded'])  # noqa: E501

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

        return self.api_client.call_api(
            '/v3/subscriptions', 'POST',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='object',  # noqa: E501
            auth_settings=auth_settings,
            async_req=params.get('async_req'),
            _return_http_data_only=params.get('_return_http_data_only'),
            _preload_content=params.get('_preload_content', True),
            _request_timeout=params.get('_request_timeout'),
            collection_formats=collection_formats)

    def subscriptions_delete_subscription(self, subscription_id, **kwargs):  # noqa: E501
        """Delete an existing subscription.  # noqa: E501

        Only Curators can use this API endpoint.  Subscriptions can only be deleted if no workflows or users are in the studio.  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.subscriptions_delete_subscription(subscription_id, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str subscription_id: Identifier for an existing subscription. (required)
        :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.subscriptions_delete_subscription_with_http_info(subscription_id, **kwargs)  # noqa: E501
        else:
            (data) = self.subscriptions_delete_subscription_with_http_info(subscription_id, **kwargs)  # noqa: E501
            return data

    def subscriptions_delete_subscription_with_http_info(self, subscription_id, **kwargs):  # noqa: E501
        """Delete an existing subscription.  # noqa: E501

        Only Curators can use this API endpoint.  Subscriptions can only be deleted if no workflows or users are in the studio.  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.subscriptions_delete_subscription_with_http_info(subscription_id, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str subscription_id: Identifier for an existing subscription. (required)
        :return: None
                 If the method is called asynchronously,
                 returns the request thread.
        """

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

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

        collection_formats = {}

        path_params = {}

        query_params = []
        if 'subscription_id' in params:
            query_params.append(('subscriptionId', params['subscription_id']))  # 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/json', 'text/json', 'application/xml', 'text/xml'])  # noqa: E501

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

        return self.api_client.call_api(
            '/v3/subscriptions', '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=params.get('async_req'),
            _return_http_data_only=params.get('_return_http_data_only'),
            _preload_content=params.get('_preload_content', True),
            _request_timeout=params.get('_request_timeout'),
            collection_formats=collection_formats)

    def subscriptions_get_subscription_by_id(self, subscription_id, **kwargs):  # noqa: E501
        """Retrieve details about an existing subscription.  # noqa: E501

        Only Curators can use this API endpoint.  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.subscriptions_get_subscription_by_id(subscription_id, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str subscription_id: Identifier for an existing subscription. (required)
        :return: SubscriptionUserWorkflowDetailsView
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('async_req'):
            return self.subscriptions_get_subscription_by_id_with_http_info(subscription_id, **kwargs)  # noqa: E501
        else:
            (data) = self.subscriptions_get_subscription_by_id_with_http_info(subscription_id, **kwargs)  # noqa: E501
            return data

    def subscriptions_get_subscription_by_id_with_http_info(self, subscription_id, **kwargs):  # noqa: E501
        """Retrieve details about an existing subscription.  # noqa: E501

        Only Curators can use this API endpoint.  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.subscriptions_get_subscription_by_id_with_http_info(subscription_id, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str subscription_id: Identifier for an existing subscription. (required)
        :return: SubscriptionUserWorkflowDetailsView
                 If the method is called asynchronously,
                 returns the request thread.
        """

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

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

        collection_formats = {}

        path_params = {}
        if 'subscription_id' in params:
            path_params['subscriptionId'] = params['subscription_id']  # noqa: E501

        query_params = []

        header_params = {}

        form_params = []
        local_var_files = {}

        body_params = None
        # HTTP header `Accept`
        header_params['Accept'] = self.api_client.select_header_accept(
            ['application/json', 'text/json', 'application/xml', 'text/xml'])  # noqa: E501

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

        return self.api_client.call_api(
            '/v3/subscriptions/{subscriptionId}', 'GET',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='SubscriptionUserWorkflowDetailsView',  # noqa: E501
            auth_settings=auth_settings,
            async_req=params.get('async_req'),
            _return_http_data_only=params.get('_return_http_data_only'),
            _preload_content=params.get('_preload_content', True),
            _request_timeout=params.get('_request_timeout'),
            collection_formats=collection_formats)

    def subscriptions_get_subscriptions(self, **kwargs):  # noqa: E501
        """Retrieve details about existing subscriptions.  # noqa: E501

        Only Curators can use this API endpoint.  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.subscriptions_get_subscriptions(async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str name:
        :param bool can_share_schedule:
        :param str default_workflow_credential_id:
        :param int user_count_greater_than_equals:
        :param int user_count_less_than_equals:
        :param int workflow_count_greater_than_equals:
        :param int workflow_count_less_than_equals:
        :return: list[SubscriptionUserWorkflowCountView]
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('async_req'):
            return self.subscriptions_get_subscriptions_with_http_info(**kwargs)  # noqa: E501
        else:
            (data) = self.subscriptions_get_subscriptions_with_http_info(**kwargs)  # noqa: E501
            return data

    def subscriptions_get_subscriptions_with_http_info(self, **kwargs):  # noqa: E501
        """Retrieve details about existing subscriptions.  # noqa: E501

        Only Curators can use this API endpoint.  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.subscriptions_get_subscriptions_with_http_info(async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str name:
        :param bool can_share_schedule:
        :param str default_workflow_credential_id:
        :param int user_count_greater_than_equals:
        :param int user_count_less_than_equals:
        :param int workflow_count_greater_than_equals:
        :param int workflow_count_less_than_equals:
        :return: list[SubscriptionUserWorkflowCountView]
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = ['name', 'can_share_schedule', 'default_workflow_credential_id', 'user_count_greater_than_equals', 'user_count_less_than_equals', 'workflow_count_greater_than_equals', 'workflow_count_less_than_equals']  # noqa: E501
        all_params.append('async_req')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

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

        collection_formats = {}

        path_params = {}

        query_params = []
        if 'name' in params:
            query_params.append(('name', params['name']))  # noqa: E501
        if 'can_share_schedule' in params:
            query_params.append(('canShareSchedule', params['can_share_schedule']))  # noqa: E501
        if 'default_workflow_credential_id' in params:
            query_params.append(('defaultWorkflowCredentialId', params['default_workflow_credential_id']))  # noqa: E501
        if 'user_count_greater_than_equals' in params:
            query_params.append(('userCountGreaterThanEquals', params['user_count_greater_than_equals']))  # noqa: E501
        if 'user_count_less_than_equals' in params:
            query_params.append(('userCountLessThanEquals', params['user_count_less_than_equals']))  # noqa: E501
        if 'workflow_count_greater_than_equals' in params:
            query_params.append(('workflowCountGreaterThanEquals', params['workflow_count_greater_than_equals']))  # noqa: E501
        if 'workflow_count_less_than_equals' in params:
            query_params.append(('workflowCountLessThanEquals', params['workflow_count_less_than_equals']))  # 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/json', 'text/json', 'application/xml', 'text/xml'])  # noqa: E501

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

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

    def subscriptions_update_subscription(self, subscription_id, subscription, **kwargs):  # noqa: E501
        """Update an existing subscription.  # noqa: E501

        Only Curators can use this API endpoint.  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.subscriptions_update_subscription(subscription_id, subscription, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str subscription_id: Identifier for an existing subscription. (required)
        :param UpdateSubscriptionContract subscription:  (required)
        :return: SubscriptionView
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('async_req'):
            return self.subscriptions_update_subscription_with_http_info(subscription_id, subscription, **kwargs)  # noqa: E501
        else:
            (data) = self.subscriptions_update_subscription_with_http_info(subscription_id, subscription, **kwargs)  # noqa: E501
            return data

    def subscriptions_update_subscription_with_http_info(self, subscription_id, subscription, **kwargs):  # noqa: E501
        """Update an existing subscription.  # noqa: E501

        Only Curators can use this API endpoint.  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.subscriptions_update_subscription_with_http_info(subscription_id, subscription, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str subscription_id: Identifier for an existing subscription. (required)
        :param UpdateSubscriptionContract subscription:  (required)
        :return: SubscriptionView
                 If the method is called asynchronously,
                 returns the request thread.
        """

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

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

        collection_formats = {}

        path_params = {}
        if 'subscription_id' in params:
            path_params['subscriptionId'] = params['subscription_id']  # noqa: E501

        query_params = []

        header_params = {}

        form_params = []
        local_var_files = {}

        body_params = None
        if 'subscription' in params:
            body_params = params['subscription']
        # HTTP header `Accept`
        header_params['Accept'] = self.api_client.select_header_accept(
            ['application/json', 'text/json', 'application/xml', 'text/xml'])  # noqa: E501

        # HTTP header `Content-Type`
        header_params['Content-Type'] = self.api_client.select_header_content_type(  # noqa: E501
            ['application/json', 'text/json', 'application/xml', 'text/xml', 'application/x-www-form-urlencoded'])  # noqa: E501

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

        return self.api_client.call_api(
            '/v3/subscriptions/{subscriptionId}', 'PUT',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='SubscriptionView',  # noqa: E501
            auth_settings=auth_settings,
            async_req=params.get('async_req'),
            _return_http_data_only=params.get('_return_http_data_only'),
            _preload_content=params.get('_preload_content', True),
            _request_timeout=params.get('_request_timeout'),
            collection_formats=collection_formats)
