# 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.0.6
    
    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 ReadingsApi(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 analytics_query(self, organization_id, **kwargs):  # noqa: E501
        """Query reading anlaytics  # noqa: E501

        Queries readings and performs anayltics operations on the them over a sample  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.analytics_query(organization_id, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str organization_id: id of Organization to retrieve (required)
        :param datetime start_date: Start date and time for the query in RFC3339 format
        :param datetime end_date: End date and time for the query in RFC3339 format
        :param list[str] fields: The fields to return readings for
        :param list[str] probes: The probes to return readings for
        :param list[str] properties: The properties to return readings for
        :param str operation: Operation to perform on reading data
        :param str sample_rate: The operation sample interval, i.e. `15m`
        :param int limit: limit the number of returns per depth
        :param bool extended: Return extended attributes
        :param bool sort: return a sorted array, will decrease performance
        :return: list[Reading]
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('async_req'):
            return self.analytics_query_with_http_info(organization_id, **kwargs)  # noqa: E501
        else:
            (data) = self.analytics_query_with_http_info(organization_id, **kwargs)  # noqa: E501
            return data

    def analytics_query_with_http_info(self, organization_id, **kwargs):  # noqa: E501
        """Query reading anlaytics  # noqa: E501

        Queries readings and performs anayltics operations on the them over a sample  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.analytics_query_with_http_info(organization_id, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str organization_id: id of Organization to retrieve (required)
        :param datetime start_date: Start date and time for the query in RFC3339 format
        :param datetime end_date: End date and time for the query in RFC3339 format
        :param list[str] fields: The fields to return readings for
        :param list[str] probes: The probes to return readings for
        :param list[str] properties: The properties to return readings for
        :param str operation: Operation to perform on reading data
        :param str sample_rate: The operation sample interval, i.e. `15m`
        :param int limit: limit the number of returns per depth
        :param bool extended: Return extended attributes
        :param bool sort: return a sorted array, will decrease performance
        :return: list[Reading]
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = ['organization_id', 'start_date', 'end_date', 'fields', 'probes', 'properties', 'operation', 'sample_rate', 'limit', 'extended', 'sort']  # 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 analytics_query" % key
                )
            params[key] = val
        del params['kwargs']
        # verify the required parameter 'organization_id' is set
        if ('organization_id' not in params or
                params['organization_id'] is None):
            raise ValueError("Missing the required parameter `organization_id` when calling `analytics_query`")  # noqa: E501

        collection_formats = {}

        path_params = {}
        if 'organization_id' in params:
            path_params['organization_id'] = params['organization_id']  # noqa: E501

        query_params = []
        if 'start_date' in params:
            query_params.append(('start_date', params['start_date']))  # noqa: E501
        if 'end_date' in params:
            query_params.append(('end_date', params['end_date']))  # noqa: E501
        if 'fields' in params:
            query_params.append(('fields', params['fields']))  # noqa: E501
            collection_formats['fields'] = 'csv'  # noqa: E501
        if 'probes' in params:
            query_params.append(('probes', params['probes']))  # noqa: E501
            collection_formats['probes'] = 'csv'  # noqa: E501
        if 'properties' in params:
            query_params.append(('properties', params['properties']))  # noqa: E501
            collection_formats['properties'] = 'csv'  # noqa: E501
        if 'operation' in params:
            query_params.append(('operation', params['operation']))  # noqa: E501
        if 'sample_rate' in params:
            query_params.append(('sample_rate', params['sample_rate']))  # noqa: E501
        if 'limit' in params:
            query_params.append(('limit', params['limit']))  # noqa: E501
        if 'extended' in params:
            query_params.append(('extended', params['extended']))  # noqa: E501
        if 'sort' in params:
            query_params.append(('sort', params['sort']))  # 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(
            '/organizations/{organization_id}/analytics', 'GET',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='list[Reading]',  # 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)

    def readings_query(self, organization_id, **kwargs):  # noqa: E501
        """Query sensor readings  # noqa: E501

        Query sensor readings associated with organization  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.readings_query(organization_id, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str organization_id: id of Organization to retrieve (required)
        :param datetime start_date: Start date and time for the query in RFC3339 format, the default is 24h prior 
        :param datetime end_date: End date and time for the query in RFC3339 format, the implied default is now 
        :param list[str] fields: The fields to return readings for
        :param list[str] probes: The probes to return readings for
        :param list[str] properties: The properties to return readings for
        :param bool extended: Return extended attributes
        :return: list[Reading]
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('async_req'):
            return self.readings_query_with_http_info(organization_id, **kwargs)  # noqa: E501
        else:
            (data) = self.readings_query_with_http_info(organization_id, **kwargs)  # noqa: E501
            return data

    def readings_query_with_http_info(self, organization_id, **kwargs):  # noqa: E501
        """Query sensor readings  # noqa: E501

        Query sensor readings associated with organization  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.readings_query_with_http_info(organization_id, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str organization_id: id of Organization to retrieve (required)
        :param datetime start_date: Start date and time for the query in RFC3339 format, the default is 24h prior 
        :param datetime end_date: End date and time for the query in RFC3339 format, the implied default is now 
        :param list[str] fields: The fields to return readings for
        :param list[str] probes: The probes to return readings for
        :param list[str] properties: The properties to return readings for
        :param bool extended: Return extended attributes
        :return: list[Reading]
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = ['organization_id', 'start_date', 'end_date', 'fields', 'probes', 'properties', 'extended']  # 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 readings_query" % key
                )
            params[key] = val
        del params['kwargs']
        # verify the required parameter 'organization_id' is set
        if ('organization_id' not in params or
                params['organization_id'] is None):
            raise ValueError("Missing the required parameter `organization_id` when calling `readings_query`")  # noqa: E501

        collection_formats = {}

        path_params = {}
        if 'organization_id' in params:
            path_params['organization_id'] = params['organization_id']  # noqa: E501

        query_params = []
        if 'start_date' in params:
            query_params.append(('start_date', params['start_date']))  # noqa: E501
        if 'end_date' in params:
            query_params.append(('end_date', params['end_date']))  # noqa: E501
        if 'fields' in params:
            query_params.append(('fields', params['fields']))  # noqa: E501
            collection_formats['fields'] = 'csv'  # noqa: E501
        if 'probes' in params:
            query_params.append(('probes', params['probes']))  # noqa: E501
            collection_formats['probes'] = 'csv'  # noqa: E501
        if 'properties' in params:
            query_params.append(('properties', params['properties']))  # noqa: E501
            collection_formats['properties'] = 'csv'  # noqa: E501
        if 'extended' in params:
            query_params.append(('extended', params['extended']))  # 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(
            '/organizations/{organization_id}/readings', 'GET',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='list[Reading]',  # 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)
