# coding: utf-8

"""
DrugsApi.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


class DrugsApi(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 get_drug_coverages(self, ndc_package_code, audience, state_code, **kwargs):
        """
        Search for DrugCoverages
        Drug Coverages are the specific tier level, quantity limit, prior
authorization and step therapy for a given Drug/Plan combination. This endpoint
returns all DrugCoverages for a given Drug

        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_drug_coverages(ndc_package_code, audience, state_code, callback=callback_function)

        :param callback function: The callback function
            for asynchronous request. (optional)
        :param str ndc_package_code: NDC package code (required)
        :param str audience: Two-character state code (required)
        :param str state_code: Two-character state code (required)
        :param str vericred_api_key: API Key
        :return: DrugCoverageResponse
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = ['ndc_package_code', 'audience', 'state_code', 'vericred_api_key']
        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 get_drug_coverages" % key
                )
            params[key] = val
        del params['kwargs']

        # verify the required parameter 'ndc_package_code' is set
        if ('ndc_package_code' not in params) or (params['ndc_package_code'] is None):
            raise ValueError("Missing the required parameter `ndc_package_code` when calling `get_drug_coverages`")
        # verify the required parameter 'audience' is set
        if ('audience' not in params) or (params['audience'] is None):
            raise ValueError("Missing the required parameter `audience` when calling `get_drug_coverages`")
        # verify the required parameter 'state_code' is set
        if ('state_code' not in params) or (params['state_code'] is None):
            raise ValueError("Missing the required parameter `state_code` when calling `get_drug_coverages`")

        resource_path = '/drug_packages/{ndc_package_code}/coverages'.replace('{format}', 'json')
        path_params = {}
        if 'ndc_package_code' in params:
            path_params['ndc_package_code'] = params['ndc_package_code']

        query_params = {}
        if 'audience' in params:
            query_params['audience'] = params['audience']
        if 'state_code' in params:
            query_params['state_code'] = params['state_code']

        header_params = {}
        if 'vericred_api_key' in params:
            header_params['Vericred-Api-Key'] = params['vericred_api_key']

        form_params = []
        local_var_files = {}

        body_params = None

        # HTTP header `Accept`
        header_params['Accept'] = self.api_client.\
            select_header_accept([])
        if not header_params['Accept']:
            del header_params['Accept']

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

        # Authentication setting
        auth_settings = []

        response = 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='DrugCoverageResponse',
                                            auth_settings=auth_settings,
                                            callback=params.get('callback'))
        return response

    def list_drugs(self, search_term, **kwargs):
        """
        Drug Search
        Search for drugs by proprietary name

        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.list_drugs(search_term, callback=callback_function)

        :param callback function: The callback function
            for asynchronous request. (optional)
        :param str search_term: Full or partial proprietary name of drug (required)
        :param str vericred_api_key: API Key
        :return: DrugSearchResponse
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = ['search_term', 'vericred_api_key']
        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 list_drugs" % key
                )
            params[key] = val
        del params['kwargs']

        # verify the required parameter 'search_term' is set
        if ('search_term' not in params) or (params['search_term'] is None):
            raise ValueError("Missing the required parameter `search_term` when calling `list_drugs`")

        resource_path = '/drugs'.replace('{format}', 'json')
        path_params = {}

        query_params = {}
        if 'search_term' in params:
            query_params['search_term'] = params['search_term']

        header_params = {}
        if 'vericred_api_key' in params:
            header_params['Vericred-Api-Key'] = params['vericred_api_key']

        form_params = []
        local_var_files = {}

        body_params = None

        # HTTP header `Accept`
        header_params['Accept'] = self.api_client.\
            select_header_accept(['application/json'])
        if not header_params['Accept']:
            del header_params['Accept']

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

        # Authentication setting
        auth_settings = []

        response = 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='DrugSearchResponse',
                                            auth_settings=auth_settings,
                                            callback=params.get('callback'))
        return response
