# coding: utf-8

"""
{{classname}}.py
Copyright 2016 SmartBear Software

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
"""

from __future__ import absolute_import

import sys
import os

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

        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 {{nickname}}" % 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 `{{nickname}}`")
{{/required}}
{{/allParams}}

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

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

        header_params = {}
{{#headerParams}}
        if '{{paramName}}' in params:
            header_params['{{baseName}}'] = params['{{paramName}}']
{{/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}}
{{/formParams}}

        body_params = None
{{#bodyParam}}
        if '{{paramName}}' in params:
            body_params = params['{{paramName}}']
{{/bodyParam}}

        # HTTP header `Accept`
        header_params['Accept'] = self.api_client.\
            select_header_accept([{{#produces}}'{{mediaType}}'{{#hasMore}}, {{/hasMore}}{{/produces}}])
        if not header_params['Accept']:
            del header_params['Accept']

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

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

        response = 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 response
{{/operation}}
{{/operations}}
