# coding: utf-8

{{>partial_header}}

from __future__ import absolute_import

import sys
import os
import re

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

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


{{#operations}}
class {{classname}}(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
{{#operation}}

    def {{operationId}}(self, {{#sortParamsByRequiredFlag}}{{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}{{/sortParamsByRequiredFlag}}**kwargs):
        """
{{#summary}}
        {{{summary}}}
{{/summary}}
{{#notes}}
        {{{notes}}}
{{/notes}}
        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)
        >>>
{{#sortParamsByRequiredFlag}}
        >>> thread = api.{{operationId}}({{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}callback=callback_function)
{{/sortParamsByRequiredFlag}}
{{^sortParamsByRequiredFlag}}
        >>> thread = api.{{operationId}}({{#allParams}}{{#required}}{{paramName}}={{paramName}}_value, {{/required}}{{/allParams}}callback=callback_function)
{{/sortParamsByRequiredFlag}}

        :param callback function: The callback function
            for asynchronous request. (optional)
{{#allParams}}
        :param {{dataType}} {{paramName}}:{{#description}} {{{description}}}{{/description}}{{#required}} (required){{/required}}{{#optional}}(optional){{/optional}}
{{/allParams}}
        :return: {{#returnType}}{{returnType}}{{/returnType}}{{^returnType}}None{{/returnType}}
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('callback'):
            return self.{{operationId}}_with_http_info({{#sortParamsByRequiredFlag}}{{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}{{/sortParamsByRequiredFlag}}**kwargs)
        else:
            (data) = self.{{operationId}}_with_http_info({{#sortParamsByRequiredFlag}}{{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}{{/sortParamsByRequiredFlag}}**kwargs)
            return data

    def {{operationId}}_with_http_info(self, {{#sortParamsByRequiredFlag}}{{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}{{/sortParamsByRequiredFlag}}**kwargs):
        """
{{#summary}}
        {{{summary}}}
{{/summary}}
{{#notes}}
        {{{notes}}}
{{/notes}}
        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)
        >>>
{{#sortParamsByRequiredFlag}}
        >>> thread = api.{{operationId}}_with_http_info({{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}callback=callback_function)
{{/sortParamsByRequiredFlag}}
{{^sortParamsByRequiredFlag}}
        >>> thread = api.{{operationId}}_with_http_info({{#allParams}}{{#required}}{{paramName}}={{paramName}}_value, {{/required}}{{/allParams}}callback=callback_function)
{{/sortParamsByRequiredFlag}}

        :param callback function: The callback function
            for asynchronous request. (optional)
{{#allParams}}
        :param {{dataType}} {{paramName}}:{{#description}} {{{description}}}{{/description}}{{#required}} (required){{/required}}{{#optional}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/optional}}
{{/allParams}}
        :return: {{#returnType}}{{returnType}}{{/returnType}}{{^returnType}}None{{/returnType}}
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = [{{#allParams}}'{{paramName}}'{{#hasMore}}, {{/hasMore}}{{/allParams}}]
        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 {{operationId}}" % key
                )
            params[key] = val
        del params['kwargs']
{{#allParams}}
{{#required}}
        # verify the required parameter '{{paramName}}' is set
        if ('{{paramName}}' not in params) or (params['{{paramName}}'] is None):
            raise ValueError("Missing the required parameter `{{paramName}}` when calling `{{operationId}}`")
{{/required}}
{{/allParams}}

{{#allParams}}
{{#hasValidation}}
    {{#maxLength}}
        if '{{paramName}}' in params and len(params['{{paramName}}']) > {{maxLength}}:
            raise ValueError("Invalid value for parameter `{{paramName}}` when calling `{{operationId}}`, length must be less than or equal to `{{maxLength}}`")
    {{/maxLength}}
    {{#minLength}}
        if '{{paramName}}' in params and len(params['{{paramName}}']) < {{minLength}}:
            raise ValueError("Invalid value for parameter `{{paramName}}` when calling `{{operationId}}`, length must be greater than or equal to `{{minLength}}`")
    {{/minLength}}
    {{#maximum}}
        if '{{paramName}}' in params and params['{{paramName}}'] >{{#exclusiveMaximum}}={{/exclusiveMaximum}} {{maximum}}:
            raise ValueError("Invalid value for parameter `{{paramName}}` when calling `{{operationId}}`, must be a value less than {{^exclusiveMaximum}}or equal to {{/exclusiveMaximum}}`{{maximum}}`")
    {{/maximum}}
    {{#minimum}}
        if '{{paramName}}' in params and params['{{paramName}}'] <{{#exclusiveMinimum}}={{/exclusiveMinimum}} {{minimum}}:
            raise ValueError("Invalid value for parameter `{{paramName}}` when calling `{{operationId}}`, must be a value greater than {{^exclusiveMinimum}}or equal to {{/exclusiveMinimum}}`{{minimum}}`")
    {{/minimum}}
    {{#pattern}}
        if '{{paramName}}' in params and not re.search('{{{vendorExtensions.x-regex}}}', params['{{paramName}}']{{#vendorExtensions.x-modifiers}}{{#-first}}, flags={{/-first}}re.{{.}}{{^-last}} | {{/-last}}{{/vendorExtensions.x-modifiers}}):
            raise ValueError("Invalid value for parameter `{{paramName}}` when calling `{{operationId}}`, must conform to the pattern `{{{pattern}}}`")
    {{/pattern}}
    {{#maxItems}}
        if '{{paramName}}' in params and len(params['{{paramName}}']) > {{maxItems}}:
            raise ValueError("Invalid value for parameter `{{paramName}}` when calling `{{operationId}}`, number of items must be less than or equal to `{{maxItems}}`")
    {{/maxItems}}
    {{#minItems}}
        if '{{paramName}}' in params and len(params['{{paramName}}']) < {{minItems}}:
            raise ValueError("Invalid value for parameter `{{paramName}}` when calling `{{operationId}}`, number of items must be greater than or equal to `{{minItems}}`")
    {{/minItems}}
{{/hasValidation}}
{{#-last}}

{{/-last}}
{{/allParams}}
        collection_formats = {}

        resource_path = '{{path}}'.replace('{format}', 'json')
        path_params = {}
{{#pathParams}}
        if '{{paramName}}' in params:
            path_params['{{baseName}}'] = params['{{paramName}}']{{#isListContainer}}
            collection_formats['{{baseName}}'] = '{{collectionFormat}}'{{/isListContainer}}
{{/pathParams}}

        query_params = {}
{{#queryParams}}
        if '{{paramName}}' in params:
            query_params['{{baseName}}'] = params['{{paramName}}']{{#isListContainer}}
            collection_formats['{{baseName}}'] = '{{collectionFormat}}'{{/isListContainer}}
{{/queryParams}}

        header_params = {}
{{#headerParams}}
        if '{{paramName}}' in params:
            header_params['{{baseName}}'] = params['{{paramName}}']{{#isListContainer}}
            collection_formats['{{baseName}}'] = '{{collectionFormat}}'{{/isListContainer}}
{{/headerParams}}

        form_params = []
        local_var_files = {}
{{#formParams}}
        if '{{paramName}}' in params:
            {{#notFile}}form_params.append(('{{baseName}}', params['{{paramName}}'])){{/notFile}}{{#isFile}}local_var_files['{{baseName}}'] = params['{{paramName}}']{{/isFile}}{{#isListContainer}}
            collection_formats['{{baseName}}'] = '{{collectionFormat}}'{{/isListContainer}}
{{/formParams}}

        body_params = None
{{#bodyParam}}
        if '{{paramName}}' in params:
            body_params = params['{{paramName}}']
{{/bodyParam}}
        {{#hasProduces}}
        # HTTP header `Accept`
        header_params['Accept'] = self.api_client.\
            select_header_accept([{{#produces}}'{{{mediaType}}}'{{#hasMore}}, {{/hasMore}}{{/produces}}])

        {{/hasProduces}}
        {{#hasConsumes}}
        # HTTP header `Content-Type`
        header_params['Content-Type'] = self.api_client.\
            select_header_content_type([{{#consumes}}'{{{mediaType}}}'{{#hasMore}}, {{/hasMore}}{{/consumes}}])

        {{/hasConsumes}}
        # Authentication setting
        auth_settings = [{{#authMethods}}'{{name}}'{{#hasMore}}, {{/hasMore}}{{/authMethods}}]

        return self.api_client.call_api(resource_path, '{{httpMethod}}',
                                        path_params,
                                        query_params,
                                        header_params,
                                        body=body_params,
                                        post_params=form_params,
                                        files=local_var_files,
                                        response_type={{#returnType}}'{{returnType}}'{{/returnType}}{{^returnType}}None{{/returnType}},
                                        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)
{{/operation}}
{{/operations}}
