# coding: utf-8

"""
    teralytic

    The Teralytic API allows clients to manage their organization, view their fields and and probes, and query sensor readings and analytics.  For sandbox testing you may use the api key: `swagger.teralytic.io`   # noqa: E501

    OpenAPI spec version: 1.1.0
    
    Generated by: https://github.com/swagger-api/swagger-codegen.git
"""


from __future__ import absolute_import

import re  # noqa: F401

# python 2 and python 3 compatibility library
import six

from teralytic.api_client import ApiClient


class SoilsApi(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):
        if api_client is None:
            api_client = ApiClient()
        self.api_client = api_client

    def query(self, geometry, **kwargs):  # noqa: E501
        """Query the soildb  # noqa: E501

        Query the soildb using various parameters  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.query(geometry, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str geometry: The geometry to query (required)
        :param str component: Filter on component values
        :param list[str] component_fields: The horizon fields to return
        :param str horizon: Filter on horizons
        :param list[str] horizon_fields: The horizon fields to return
        :return: FeatureCollection
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('async_req'):
            return self.query_with_http_info(geometry, **kwargs)  # noqa: E501
        else:
            (data) = self.query_with_http_info(geometry, **kwargs)  # noqa: E501
            return data

    def query_with_http_info(self, geometry, **kwargs):  # noqa: E501
        """Query the soildb  # noqa: E501

        Query the soildb using various parameters  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.query_with_http_info(geometry, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str geometry: The geometry to query (required)
        :param str component: Filter on component values
        :param list[str] component_fields: The horizon fields to return
        :param str horizon: Filter on horizons
        :param list[str] horizon_fields: The horizon fields to return
        :return: FeatureCollection
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = ['geometry', 'component', 'component_fields', 'horizon', 'horizon_fields']  # noqa: E501
        all_params.append('async_req')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

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

        collection_formats = {}

        path_params = {}

        query_params = []
        if 'geometry' in params:
            query_params.append(('geometry', params['geometry']))  # noqa: E501
        if 'component' in params:
            query_params.append(('component', params['component']))  # noqa: E501
        if 'component_fields' in params:
            query_params.append(('component_fields', params['component_fields']))  # noqa: E501
            collection_formats['component_fields'] = 'csv'  # noqa: E501
        if 'horizon' in params:
            query_params.append(('horizon', params['horizon']))  # noqa: E501
        if 'horizon_fields' in params:
            query_params.append(('horizon_fields', params['horizon_fields']))  # noqa: E501
            collection_formats['horizon_fields'] = 'csv'  # noqa: E501

        header_params = {}

        form_params = []
        local_var_files = {}

        body_params = None
        # HTTP header `Accept`
        header_params['Accept'] = self.api_client.select_header_accept(
            ['application/json'])  # noqa: E501

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

        # Authentication setting
        auth_settings = ['ApiKeyAuth', 'OAuth2']  # noqa: E501

        return self.api_client.call_api(
            '/soils', 'GET',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='FeatureCollection',  # noqa: E501
            auth_settings=auth_settings,
            async_req=params.get('async_req'),
            _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)
