# coding: utf-8

"""
    Maestro API

    Maestro authors and executes experiences that allow non-coders the ability to define Simple Business Process without having to write code and to deploy them seamlessly without having to have development expertise  # noqa: E501

    OpenAPI spec version: 1.0.0
    Contact: devcenter@docusign.com
    Generated by: https://github.com/swagger-api/swagger-codegen.git
"""


from __future__ import absolute_import

import sys
import os
import re

# python 2 and python 3 compatibility library
from six import iteritems

from ..client.configuration import Configuration
from ..client.api_client import ApiClient


class WorkflowInstanceManagementApi(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):
        config = Configuration()
        if api_client:
            self.api_client = api_client
        else:
            if not config.api_client:
                config.api_client = ApiClient()
            self.api_client = config.api_client

    def cancel_workflow_instance(self, account_id, instance_id, **kwargs):
        """
        Cancels a running workflow instance.
        Cancels a running workflow instance.
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please define a `callback` function
        to be invoked when receiving the response.
        >>> def callback_function(response):
        >>>     pprint(response)
        >>>
        >>> thread = api.cancel_workflow_instance(account_id, instance_id, callback=callback_function)

        :param callback function: The callback function
            for asynchronous request. (optional)
        :param str account_id: Account ID (required)
        :param str instance_id: DS Workflow Instance Id (dacId) (required)
        :return: CancelResponse
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('callback'):
            return self.cancel_workflow_instance_with_http_info(account_id, instance_id, **kwargs)
        else:
            (data) = self.cancel_workflow_instance_with_http_info(account_id, instance_id, **kwargs)
            return data

    def cancel_workflow_instance_with_http_info(self, account_id, instance_id, **kwargs):
        """
        Cancels a running workflow instance.
        Cancels a running workflow instance.
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please define a `callback` function
        to be invoked when receiving the response.
        >>> def callback_function(response):
        >>>     pprint(response)
        >>>
        >>> thread = api.cancel_workflow_instance_with_http_info(account_id, instance_id, callback=callback_function)

        :param callback function: The callback function
            for asynchronous request. (optional)
        :param str account_id: Account ID (required)
        :param str instance_id: DS Workflow Instance Id (dacId) (required)
        :return: CancelResponse
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = ['account_id', 'instance_id']
        all_params.append('callback')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

        params = locals()
        for key, val in iteritems(params['kwargs']):
            if key not in all_params:
                raise TypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method cancel_workflow_instance" % key
                )
            params[key] = val
        del params['kwargs']
        # verify the required parameter 'account_id' is set
        if ('account_id' not in params) or (params['account_id'] is None):
            raise ValueError("Missing the required parameter `account_id` when calling `cancel_workflow_instance`")
        # verify the required parameter 'instance_id' is set
        if ('instance_id' not in params) or (params['instance_id'] is None):
            raise ValueError("Missing the required parameter `instance_id` when calling `cancel_workflow_instance`")


        collection_formats = {}

        resource_path = '/v1/accounts/{accountId}/management/instances/{instanceId}/cancel'.replace('{format}', 'json')
        path_params = {}
        if 'account_id' in params:
            path_params['accountId'] = params['account_id']
        if 'instance_id' in params:
            path_params['instanceId'] = params['instance_id']

        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'])

        # HTTP header `Content-Type`
        header_params['Content-Type'] = self.api_client.\
            select_header_content_type(['application/json'])

        # Authentication setting
        auth_settings = []

        return self.api_client.call_api(resource_path, 'POST',
                                        path_params,
                                        query_params,
                                        header_params,
                                        body=body_params,
                                        post_params=form_params,
                                        files=local_var_files,
                                        response_type='CancelResponse',
                                        auth_settings=auth_settings,
                                        callback=params.get('callback'),
                                        _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 get_workflow_history(self, account_id, instance_id, **kwargs):
        """
        Get List of Step Histories
        Returns a list of step history for a workflow instance
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please define a `callback` function
        to be invoked when receiving the response.
        >>> def callback_function(response):
        >>>     pprint(response)
        >>>
        >>> thread = api.get_workflow_history(account_id, instance_id, callback=callback_function)

        :param callback function: The callback function
            for asynchronous request. (optional)
        :param str account_id: Account ID (required)
        :param str instance_id: DS Workflow Instance Id (dacId) (required)
        :return: list[WorkflowStepHistory]
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('callback'):
            return self.get_workflow_history_with_http_info(account_id, instance_id, **kwargs)
        else:
            (data) = self.get_workflow_history_with_http_info(account_id, instance_id, **kwargs)
            return data

    def get_workflow_history_with_http_info(self, account_id, instance_id, **kwargs):
        """
        Get List of Step Histories
        Returns a list of step history for a workflow instance
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please define a `callback` function
        to be invoked when receiving the response.
        >>> def callback_function(response):
        >>>     pprint(response)
        >>>
        >>> thread = api.get_workflow_history_with_http_info(account_id, instance_id, callback=callback_function)

        :param callback function: The callback function
            for asynchronous request. (optional)
        :param str account_id: Account ID (required)
        :param str instance_id: DS Workflow Instance Id (dacId) (required)
        :return: list[WorkflowStepHistory]
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = ['account_id', 'instance_id']
        all_params.append('callback')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

        params = locals()
        for key, val in iteritems(params['kwargs']):
            if key not in all_params:
                raise TypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method get_workflow_history" % key
                )
            params[key] = val
        del params['kwargs']
        # verify the required parameter 'account_id' is set
        if ('account_id' not in params) or (params['account_id'] is None):
            raise ValueError("Missing the required parameter `account_id` when calling `get_workflow_history`")
        # verify the required parameter 'instance_id' is set
        if ('instance_id' not in params) or (params['instance_id'] is None):
            raise ValueError("Missing the required parameter `instance_id` when calling `get_workflow_history`")


        collection_formats = {}

        resource_path = '/v1/accounts/{accountId}/management/instances/{instanceId}/history'.replace('{format}', 'json')
        path_params = {}
        if 'account_id' in params:
            path_params['accountId'] = params['account_id']
        if 'instance_id' in params:
            path_params['instanceId'] = params['instance_id']

        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'])

        # HTTP header `Content-Type`
        header_params['Content-Type'] = self.api_client.\
            select_header_content_type(['application/json'])

        # Authentication setting
        auth_settings = []

        return self.api_client.call_api(resource_path, 'GET',
                                        path_params,
                                        query_params,
                                        header_params,
                                        body=body_params,
                                        post_params=form_params,
                                        files=local_var_files,
                                        response_type='list[WorkflowStepHistory]',
                                        auth_settings=auth_settings,
                                        callback=params.get('callback'),
                                        _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 get_workflow_instance(self, account_id, workflow_definition_id, instance_id, **kwargs):
        """
        Get Workflow Instance Details
        Returns the details for a specific instance for a deployed workflow definition.
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please define a `callback` function
        to be invoked when receiving the response.
        >>> def callback_function(response):
        >>>     pprint(response)
        >>>
        >>> thread = api.get_workflow_instance(account_id, workflow_definition_id, instance_id, callback=callback_function)

        :param callback function: The callback function
            for asynchronous request. (optional)
        :param str account_id: Account ID (required)
        :param str workflow_definition_id: Workflow Definition ID (required)
        :param str instance_id: DS Workflow Instance Id (dacId) (required)
        :return: WorkflowInstance
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('callback'):
            return self.get_workflow_instance_with_http_info(account_id, workflow_definition_id, instance_id, **kwargs)
        else:
            (data) = self.get_workflow_instance_with_http_info(account_id, workflow_definition_id, instance_id, **kwargs)
            return data

    def get_workflow_instance_with_http_info(self, account_id, workflow_definition_id, instance_id, **kwargs):
        """
        Get Workflow Instance Details
        Returns the details for a specific instance for a deployed workflow definition.
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please define a `callback` function
        to be invoked when receiving the response.
        >>> def callback_function(response):
        >>>     pprint(response)
        >>>
        >>> thread = api.get_workflow_instance_with_http_info(account_id, workflow_definition_id, instance_id, callback=callback_function)

        :param callback function: The callback function
            for asynchronous request. (optional)
        :param str account_id: Account ID (required)
        :param str workflow_definition_id: Workflow Definition ID (required)
        :param str instance_id: DS Workflow Instance Id (dacId) (required)
        :return: WorkflowInstance
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = ['account_id', 'workflow_definition_id', 'instance_id']
        all_params.append('callback')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

        params = locals()
        for key, val in iteritems(params['kwargs']):
            if key not in all_params:
                raise TypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method get_workflow_instance" % key
                )
            params[key] = val
        del params['kwargs']
        # verify the required parameter 'account_id' is set
        if ('account_id' not in params) or (params['account_id'] is None):
            raise ValueError("Missing the required parameter `account_id` when calling `get_workflow_instance`")
        # verify the required parameter 'workflow_definition_id' is set
        if ('workflow_definition_id' not in params) or (params['workflow_definition_id'] is None):
            raise ValueError("Missing the required parameter `workflow_definition_id` when calling `get_workflow_instance`")
        # verify the required parameter 'instance_id' is set
        if ('instance_id' not in params) or (params['instance_id'] is None):
            raise ValueError("Missing the required parameter `instance_id` when calling `get_workflow_instance`")


        collection_formats = {}

        resource_path = '/v1/accounts/{accountId}/management/workflow_definitions/{workflowDefinitionId}/instances/{instanceId}'.replace('{format}', 'json')
        path_params = {}
        if 'account_id' in params:
            path_params['accountId'] = params['account_id']
        if 'workflow_definition_id' in params:
            path_params['workflowDefinitionId'] = params['workflow_definition_id']
        if 'instance_id' in params:
            path_params['instanceId'] = params['instance_id']

        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'])

        # HTTP header `Content-Type`
        header_params['Content-Type'] = self.api_client.\
            select_header_content_type(['application/json'])

        # Authentication setting
        auth_settings = []

        return self.api_client.call_api(resource_path, 'GET',
                                        path_params,
                                        query_params,
                                        header_params,
                                        body=body_params,
                                        post_params=form_params,
                                        files=local_var_files,
                                        response_type='WorkflowInstance',
                                        auth_settings=auth_settings,
                                        callback=params.get('callback'),
                                        _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 get_workflow_instances(self, account_id, workflow_definition_id, **kwargs):
        """
        Get List of Workflow Instances
        Returns the list of instances for a deployed workflow definition.
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please define a `callback` function
        to be invoked when receiving the response.
        >>> def callback_function(response):
        >>>     pprint(response)
        >>>
        >>> thread = api.get_workflow_instances(account_id, workflow_definition_id, callback=callback_function)

        :param callback function: The callback function
            for asynchronous request. (optional)
        :param str account_id: Account ID (required)
        :param str workflow_definition_id: Workflow Definition ID (required)
        :return: list[WorkflowInstance]
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('callback'):
            return self.get_workflow_instances_with_http_info(account_id, workflow_definition_id, **kwargs)
        else:
            (data) = self.get_workflow_instances_with_http_info(account_id, workflow_definition_id, **kwargs)
            return data

    def get_workflow_instances_with_http_info(self, account_id, workflow_definition_id, **kwargs):
        """
        Get List of Workflow Instances
        Returns the list of instances for a deployed workflow definition.
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please define a `callback` function
        to be invoked when receiving the response.
        >>> def callback_function(response):
        >>>     pprint(response)
        >>>
        >>> thread = api.get_workflow_instances_with_http_info(account_id, workflow_definition_id, callback=callback_function)

        :param callback function: The callback function
            for asynchronous request. (optional)
        :param str account_id: Account ID (required)
        :param str workflow_definition_id: Workflow Definition ID (required)
        :return: list[WorkflowInstance]
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = ['account_id', 'workflow_definition_id']
        all_params.append('callback')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

        params = locals()
        for key, val in iteritems(params['kwargs']):
            if key not in all_params:
                raise TypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method get_workflow_instances" % key
                )
            params[key] = val
        del params['kwargs']
        # verify the required parameter 'account_id' is set
        if ('account_id' not in params) or (params['account_id'] is None):
            raise ValueError("Missing the required parameter `account_id` when calling `get_workflow_instances`")
        # verify the required parameter 'workflow_definition_id' is set
        if ('workflow_definition_id' not in params) or (params['workflow_definition_id'] is None):
            raise ValueError("Missing the required parameter `workflow_definition_id` when calling `get_workflow_instances`")


        collection_formats = {}

        resource_path = '/v1/accounts/{accountId}/management/workflow_definitions/{workflowDefinitionId}/instances'.replace('{format}', 'json')
        path_params = {}
        if 'account_id' in params:
            path_params['accountId'] = params['account_id']
        if 'workflow_definition_id' in params:
            path_params['workflowDefinitionId'] = params['workflow_definition_id']

        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'])

        # HTTP header `Content-Type`
        header_params['Content-Type'] = self.api_client.\
            select_header_content_type(['application/json'])

        # Authentication setting
        auth_settings = []

        return self.api_client.call_api(resource_path, 'GET',
                                        path_params,
                                        query_params,
                                        header_params,
                                        body=body_params,
                                        post_params=form_params,
                                        files=local_var_files,
                                        response_type='list[WorkflowInstance]',
                                        auth_settings=auth_settings,
                                        callback=params.get('callback'),
                                        _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)
