# coding: utf-8

"""
    Onshape REST API

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

    The version of the OpenAPI document: 1.113
    Contact: api-support@onshape.zendesk.com
    Generated by: https://openapi-generator.tech
"""


from __future__ import absolute_import

import re  # noqa: F401
import sys  # noqa: F401

# python 2 and python 3 compatibility library
import six

from onshape_client.oas.api_client import ApiClient
from onshape_client.oas.exceptions import ApiTypeError, ApiValueError
from onshape_client.oas.model_utils import (  # noqa: F401
    check_allowed_values,
    check_validations,
    date,
    datetime,
    file_type,
    int,
    none_type,
    str,
    validate_and_convert_types,
)
from onshape_client.oas.models import bt_release_package_params
from onshape_client.oas.models import bt_active_workflow_info
from onshape_client.oas.models import bt_release_package_info
from onshape_client.oas.models import bt_update_release_package_params


class ReleaseManagementApi(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 __create_obsoletion_package(self, wfid, **kwargs):
            """create_obsoletion_package  # noqa: E501

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

            Args:
                wfid (str):

            Keyword Args:
                revision_id (str): [optional]
                _return_http_data_only (bool): response data without head status
                    code and headers. Default is True.
                _preload_content (bool): if False, the urllib3.HTTPResponse object
                    will be returned without reading/decoding response data.
                    Default is True.
                _request_timeout (float/tuple): timeout setting for this request. If one
                    number provided, it will be total request timeout. It can also
                    be a pair (tuple) of (connection, read) timeouts.
                    Default is None.
                _check_input_type (bool): specifies if type checking
                    should be done one the data sent to the server.
                    Default is True.
                _check_return_type (bool): specifies if type checking
                    should be done one the data received from the server.
                    Default is True.
                _host_index (int): specifies the index of the server
                    that we want to use.
                    Default is 0.
                async_req (bool): execute request asynchronously

            Returns:
                None
                    If the method is called asynchronously, returns the request
                    thread.
            """
            kwargs["async_req"] = kwargs.get("async_req", False)
            kwargs["_return_http_data_only"] = kwargs.get(
                "_return_http_data_only", True
            )
            kwargs["_preload_content"] = kwargs.get("_preload_content", True)
            kwargs["_request_timeout"] = kwargs.get("_request_timeout", None)
            kwargs["_check_input_type"] = kwargs.get("_check_input_type", True)
            kwargs["_check_return_type"] = kwargs.get("_check_return_type", True)
            kwargs["_host_index"] = kwargs.get("_host_index", 0)
            kwargs["wfid"] = wfid
            return self.call_with_http_info(**kwargs)

        self.create_obsoletion_package = Endpoint(
            settings={
                "response_type": None,
                "auth": ["OAuth2"],
                "endpoint_path": "/api/releasepackages/obsoletion/{wfid}",
                "operation_id": "create_obsoletion_package",
                "http_method": "POST",
                "servers": [],
            },
            params_map={
                "all": ["wfid", "revision_id",],
                "required": ["wfid",],
                "nullable": [],
                "enum": [],
                "validation": [],
            },
            root_map={
                "validations": {},
                "allowed_values": {},
                "openapi_types": {"wfid": (str,), "revision_id": (str,),},
                "attribute_map": {"wfid": "wfid", "revision_id": "revisionId",},
                "location_map": {"wfid": "path", "revision_id": "query",},
                "collection_format_map": {},
            },
            headers_map={
                "accept": ["application/vnd.onshape.v1+json;charset=UTF-8;qs=0.1"],
                "content_type": [],
            },
            api_client=api_client,
            callable=__create_obsoletion_package,
        )

        def __create_release_package(self, wfid, bt_release_package_params, **kwargs):
            """create_release_package  # noqa: E501

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

            Args:
                wfid (str):
                bt_release_package_params (bt_release_package_params.BTReleasePackageParams):

            Keyword Args:
                _return_http_data_only (bool): response data without head status
                    code and headers. Default is True.
                _preload_content (bool): if False, the urllib3.HTTPResponse object
                    will be returned without reading/decoding response data.
                    Default is True.
                _request_timeout (float/tuple): timeout setting for this request. If one
                    number provided, it will be total request timeout. It can also
                    be a pair (tuple) of (connection, read) timeouts.
                    Default is None.
                _check_input_type (bool): specifies if type checking
                    should be done one the data sent to the server.
                    Default is True.
                _check_return_type (bool): specifies if type checking
                    should be done one the data received from the server.
                    Default is True.
                _host_index (int): specifies the index of the server
                    that we want to use.
                    Default is 0.
                async_req (bool): execute request asynchronously

            Returns:
                None
                    If the method is called asynchronously, returns the request
                    thread.
            """
            kwargs["async_req"] = kwargs.get("async_req", False)
            kwargs["_return_http_data_only"] = kwargs.get(
                "_return_http_data_only", True
            )
            kwargs["_preload_content"] = kwargs.get("_preload_content", True)
            kwargs["_request_timeout"] = kwargs.get("_request_timeout", None)
            kwargs["_check_input_type"] = kwargs.get("_check_input_type", True)
            kwargs["_check_return_type"] = kwargs.get("_check_return_type", True)
            kwargs["_host_index"] = kwargs.get("_host_index", 0)
            kwargs["wfid"] = wfid
            kwargs["bt_release_package_params"] = bt_release_package_params
            return self.call_with_http_info(**kwargs)

        self.create_release_package = Endpoint(
            settings={
                "response_type": None,
                "auth": ["OAuth2"],
                "endpoint_path": "/api/releasepackages/release/{wfid}",
                "operation_id": "create_release_package",
                "http_method": "POST",
                "servers": [],
            },
            params_map={
                "all": ["wfid", "bt_release_package_params",],
                "required": ["wfid", "bt_release_package_params",],
                "nullable": [],
                "enum": [],
                "validation": [],
            },
            root_map={
                "validations": {},
                "allowed_values": {},
                "openapi_types": {
                    "wfid": (str,),
                    "bt_release_package_params": (
                        bt_release_package_params.BTReleasePackageParams,
                    ),
                },
                "attribute_map": {"wfid": "wfid",},
                "location_map": {"wfid": "path", "bt_release_package_params": "body",},
                "collection_format_map": {},
            },
            headers_map={
                "accept": ["application/vnd.onshape.v1+json;charset=UTF-8;qs=0.1"],
                "content_type": ["application/json;charset=UTF-8; qs=0.09"],
            },
            api_client=api_client,
            callable=__create_release_package,
        )

        def __get_company_release_workflow(self, **kwargs):
            """get_company_release_workflow  # 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_company_release_workflow(async_req=True)
            >>> result = thread.get()


            Keyword Args:
                document_id (str): [optional]
                _return_http_data_only (bool): response data without head status
                    code and headers. Default is True.
                _preload_content (bool): if False, the urllib3.HTTPResponse object
                    will be returned without reading/decoding response data.
                    Default is True.
                _request_timeout (float/tuple): timeout setting for this request. If one
                    number provided, it will be total request timeout. It can also
                    be a pair (tuple) of (connection, read) timeouts.
                    Default is None.
                _check_input_type (bool): specifies if type checking
                    should be done one the data sent to the server.
                    Default is True.
                _check_return_type (bool): specifies if type checking
                    should be done one the data received from the server.
                    Default is True.
                _host_index (int): specifies the index of the server
                    that we want to use.
                    Default is 0.
                async_req (bool): execute request asynchronously

            Returns:
                bt_active_workflow_info.BTActiveWorkflowInfo
                    If the method is called asynchronously, returns the request
                    thread.
            """
            kwargs["async_req"] = kwargs.get("async_req", False)
            kwargs["_return_http_data_only"] = kwargs.get(
                "_return_http_data_only", True
            )
            kwargs["_preload_content"] = kwargs.get("_preload_content", True)
            kwargs["_request_timeout"] = kwargs.get("_request_timeout", None)
            kwargs["_check_input_type"] = kwargs.get("_check_input_type", True)
            kwargs["_check_return_type"] = kwargs.get("_check_return_type", True)
            kwargs["_host_index"] = kwargs.get("_host_index", 0)
            return self.call_with_http_info(**kwargs)

        self.get_company_release_workflow = Endpoint(
            settings={
                "response_type": (bt_active_workflow_info.BTActiveWorkflowInfo,),
                "auth": ["OAuth2"],
                "endpoint_path": "/api/releasepackages/companyreleaseworkflow",
                "operation_id": "get_company_release_workflow",
                "http_method": "GET",
                "servers": [],
            },
            params_map={
                "all": ["document_id",],
                "required": [],
                "nullable": [],
                "enum": [],
                "validation": [],
            },
            root_map={
                "validations": {},
                "allowed_values": {},
                "openapi_types": {"document_id": (str,),},
                "attribute_map": {"document_id": "documentId",},
                "location_map": {"document_id": "query",},
                "collection_format_map": {},
            },
            headers_map={
                "accept": ["application/vnd.onshape.v1+json;charset=UTF-8;qs=0.1"],
                "content_type": [],
            },
            api_client=api_client,
            callable=__get_company_release_workflow,
        )

        def __get_release_package(self, rpid, **kwargs):
            """get_release_package  # 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_release_package(rpid, async_req=True)
            >>> result = thread.get()

            Args:
                rpid (str):

            Keyword Args:
                detailed (bool): [optional] if omitted the server will use the default value of False
                _return_http_data_only (bool): response data without head status
                    code and headers. Default is True.
                _preload_content (bool): if False, the urllib3.HTTPResponse object
                    will be returned without reading/decoding response data.
                    Default is True.
                _request_timeout (float/tuple): timeout setting for this request. If one
                    number provided, it will be total request timeout. It can also
                    be a pair (tuple) of (connection, read) timeouts.
                    Default is None.
                _check_input_type (bool): specifies if type checking
                    should be done one the data sent to the server.
                    Default is True.
                _check_return_type (bool): specifies if type checking
                    should be done one the data received from the server.
                    Default is True.
                _host_index (int): specifies the index of the server
                    that we want to use.
                    Default is 0.
                async_req (bool): execute request asynchronously

            Returns:
                bt_release_package_info.BTReleasePackageInfo
                    If the method is called asynchronously, returns the request
                    thread.
            """
            kwargs["async_req"] = kwargs.get("async_req", False)
            kwargs["_return_http_data_only"] = kwargs.get(
                "_return_http_data_only", True
            )
            kwargs["_preload_content"] = kwargs.get("_preload_content", True)
            kwargs["_request_timeout"] = kwargs.get("_request_timeout", None)
            kwargs["_check_input_type"] = kwargs.get("_check_input_type", True)
            kwargs["_check_return_type"] = kwargs.get("_check_return_type", True)
            kwargs["_host_index"] = kwargs.get("_host_index", 0)
            kwargs["rpid"] = rpid
            return self.call_with_http_info(**kwargs)

        self.get_release_package = Endpoint(
            settings={
                "response_type": (bt_release_package_info.BTReleasePackageInfo,),
                "auth": ["OAuth2"],
                "endpoint_path": "/api/releasepackages/{rpid}",
                "operation_id": "get_release_package",
                "http_method": "GET",
                "servers": [],
            },
            params_map={
                "all": ["rpid", "detailed",],
                "required": ["rpid",],
                "nullable": [],
                "enum": [],
                "validation": [],
            },
            root_map={
                "validations": {},
                "allowed_values": {},
                "openapi_types": {"rpid": (str,), "detailed": (bool,),},
                "attribute_map": {"rpid": "rpid", "detailed": "detailed",},
                "location_map": {"rpid": "path", "detailed": "query",},
                "collection_format_map": {},
            },
            headers_map={
                "accept": ["application/vnd.onshape.v1+json;charset=UTF-8;qs=0.1"],
                "content_type": [],
            },
            api_client=api_client,
            callable=__get_release_package,
        )

        def __update_release_package(
            self, rpid, bt_update_release_package_params, **kwargs
        ):
            """update_release_package  # noqa: E501

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

            Args:
                rpid (str):
                bt_update_release_package_params (bt_update_release_package_params.BTUpdateReleasePackageParams):

            Keyword Args:
                action (str): [optional] if omitted the server will use the default value of 'UPDATE'
                wfaction (str): [optional]
                _return_http_data_only (bool): response data without head status
                    code and headers. Default is True.
                _preload_content (bool): if False, the urllib3.HTTPResponse object
                    will be returned without reading/decoding response data.
                    Default is True.
                _request_timeout (float/tuple): timeout setting for this request. If one
                    number provided, it will be total request timeout. It can also
                    be a pair (tuple) of (connection, read) timeouts.
                    Default is None.
                _check_input_type (bool): specifies if type checking
                    should be done one the data sent to the server.
                    Default is True.
                _check_return_type (bool): specifies if type checking
                    should be done one the data received from the server.
                    Default is True.
                _host_index (int): specifies the index of the server
                    that we want to use.
                    Default is 0.
                async_req (bool): execute request asynchronously

            Returns:
                bt_release_package_info.BTReleasePackageInfo
                    If the method is called asynchronously, returns the request
                    thread.
            """
            kwargs["async_req"] = kwargs.get("async_req", False)
            kwargs["_return_http_data_only"] = kwargs.get(
                "_return_http_data_only", True
            )
            kwargs["_preload_content"] = kwargs.get("_preload_content", True)
            kwargs["_request_timeout"] = kwargs.get("_request_timeout", None)
            kwargs["_check_input_type"] = kwargs.get("_check_input_type", True)
            kwargs["_check_return_type"] = kwargs.get("_check_return_type", True)
            kwargs["_host_index"] = kwargs.get("_host_index", 0)
            kwargs["rpid"] = rpid
            kwargs[
                "bt_update_release_package_params"
            ] = bt_update_release_package_params
            return self.call_with_http_info(**kwargs)

        self.update_release_package = Endpoint(
            settings={
                "response_type": (bt_release_package_info.BTReleasePackageInfo,),
                "auth": ["OAuth2"],
                "endpoint_path": "/api/releasepackages/{rpid}",
                "operation_id": "update_release_package",
                "http_method": "POST",
                "servers": [],
            },
            params_map={
                "all": [
                    "rpid",
                    "bt_update_release_package_params",
                    "action",
                    "wfaction",
                ],
                "required": ["rpid", "bt_update_release_package_params",],
                "nullable": [],
                "enum": [],
                "validation": [],
            },
            root_map={
                "validations": {},
                "allowed_values": {},
                "openapi_types": {
                    "rpid": (str,),
                    "bt_update_release_package_params": (
                        bt_update_release_package_params.BTUpdateReleasePackageParams,
                    ),
                    "action": (str,),
                    "wfaction": (str,),
                },
                "attribute_map": {
                    "rpid": "rpid",
                    "action": "action",
                    "wfaction": "wfaction",
                },
                "location_map": {
                    "rpid": "path",
                    "bt_update_release_package_params": "body",
                    "action": "query",
                    "wfaction": "query",
                },
                "collection_format_map": {},
            },
            headers_map={
                "accept": ["application/vnd.onshape.v1+json;charset=UTF-8;qs=0.1"],
                "content_type": ["application/json;charset=UTF-8; qs=0.09"],
            },
            api_client=api_client,
            callable=__update_release_package,
        )


class Endpoint(object):
    def __init__(
        self,
        settings=None,
        params_map=None,
        root_map=None,
        headers_map=None,
        api_client=None,
        callable=None,
    ):
        """Creates an endpoint

        Args:
            settings (dict): see below key value pairs
                'response_type' (tuple/None): response type
                'auth' (list): a list of auth type keys
                'endpoint_path' (str): the endpoint path
                'operation_id' (str): endpoint string identifier
                'http_method' (str): POST/PUT/PATCH/GET etc
                'servers' (list): list of str servers that this endpoint is at
            params_map (dict): see below key value pairs
                'all' (list): list of str endpoint parameter names
                'required' (list): list of required parameter names
                'nullable' (list): list of nullable parameter names
                'enum' (list): list of parameters with enum values
                'validation' (list): list of parameters with validations
            root_map
                'validations' (dict): the dict mapping endpoint parameter tuple
                    paths to their validation dictionaries
                'allowed_values' (dict): the dict mapping endpoint parameter
                    tuple paths to their allowed_values (enum) dictionaries
                'openapi_types' (dict): param_name to openapi type
                'attribute_map' (dict): param_name to camelCase name
                'location_map' (dict): param_name to  'body', 'file', 'form',
                    'header', 'path', 'query'
                collection_format_map (dict): param_name to `csv` etc.
            headers_map (dict): see below key value pairs
                'accept' (list): list of Accept header strings
                'content_type' (list): list of Content-Type header strings
            api_client (ApiClient) api client instance
            callable (function): the function which is invoked when the
                Endpoint is called
        """
        self.settings = settings
        self.params_map = params_map
        self.params_map["all"].extend(
            [
                "async_req",
                "_host_index",
                "_preload_content",
                "_request_timeout",
                "_return_http_data_only",
                "_check_input_type",
                "_check_return_type",
            ]
        )
        self.params_map["nullable"].extend(["_request_timeout"])
        self.validations = root_map["validations"]
        self.allowed_values = root_map["allowed_values"]
        self.openapi_types = root_map["openapi_types"]
        extra_types = {
            "async_req": (bool,),
            "_host_index": (int,),
            "_preload_content": (bool,),
            "_request_timeout": (none_type, int, (int,), [int]),
            "_return_http_data_only": (bool,),
            "_check_input_type": (bool,),
            "_check_return_type": (bool,),
        }
        self.openapi_types.update(extra_types)
        self.attribute_map = root_map["attribute_map"]
        self.location_map = root_map["location_map"]
        self.collection_format_map = root_map["collection_format_map"]
        self.headers_map = headers_map
        self.api_client = api_client
        self.callable = callable

    def __validate_inputs(self, kwargs):
        for param in self.params_map["enum"]:
            if param in kwargs:
                check_allowed_values(self.allowed_values, (param,), kwargs[param])

        for param in self.params_map["validation"]:
            if param in kwargs:
                check_validations(self.validations, (param,), kwargs[param])

        if kwargs["_check_input_type"] is False:
            return

        for key, value in six.iteritems(kwargs):
            fixed_val = validate_and_convert_types(
                value,
                self.openapi_types[key],
                [key],
                False,
                kwargs["_check_input_type"],
                configuration=self.api_client.configuration,
            )
            kwargs[key] = fixed_val

    def __gather_params(self, kwargs):
        params = {
            "body": None,
            "collection_format": {},
            "file": {},
            "form": [],
            "header": {},
            "path": {},
            "query": [],
        }

        for param_name, param_value in six.iteritems(kwargs):
            param_location = self.location_map.get(param_name)
            if param_location is None:
                continue
            if param_location:
                if param_location == "body":
                    params["body"] = param_value
                    continue
                base_name = self.attribute_map[param_name]
                if param_location == "form" and self.openapi_types[param_name] == (
                    file_type,
                ):
                    params["file"][param_name] = [param_value]
                elif param_location == "form" and self.openapi_types[param_name] == (
                    [file_type],
                ):