# coding: utf-8

"""
    Agilicus API

    Agilicus is API-first. Modern software is controlled by other software, is open, is available for you to use the way you want, securely, simply.  A rendered, online viewable and usable version of this specification is available at [api](https://www.agilicus.com/api). You may try the API inline directly in the web page. To do so, first obtain an Authentication Token (the simplest way is to install the Python SDK, and then run `agilicus-cli --issuer https://MYISSUER get-token`). You will need an org-id for most calls (and can obtain from `agilicus-cli --issuer https://MYISSUER list-orgs`). The `MYISSUER` will typically be `auth.MYDOMAIN`, and you will see it as you sign-in to the administrative UI.  This API releases on Bearer-Token authentication. To obtain a valid bearer token you will need to Authenticate to an Issuer with OpenID Connect (a superset of OAUTH2).  Your \"issuer\" will look like https://auth.MYDOMAIN. For example, when you signed-up, if you said \"use my own domain name\" and assigned a CNAME of cloud.example.com, then your issuer would be https://auth.cloud.example.com.  If you selected \"use an Agilicus supplied domain name\", your issuer would look like https://auth.myorg.agilicus.cloud.  For test purposes you can use our [Python SDK](https://pypi.org/project/agilicus/) and run `agilicus-cli --issuer https://auth.MYDOMAIN get-token`.  This API may be used in any language runtime that supports OpenAPI 3.0, or, you may use our [Python SDK](https://pypi.org/project/agilicus/), our [Typescript SDK](https://www.npmjs.com/package/@agilicus/angular), or our [Golang SDK](https://git.agilicus.com/pub/sdk-go).  100% of the activities in our system our API-driven, from our web-admin, through our progressive web applications, to all internals: there is nothing that is not accessible.  For more information, see [developer resources](https://www.agilicus.com/developer).   # noqa: E501

    The version of the OpenAPI document: 2021.05.14
    Contact: dev@agilicus.com
    Generated by: https://openapi-generator.tech
"""


from __future__ import absolute_import

import re  # noqa: F401

# python 2 and python 3 compatibility library
import six

from agilicus_api.api_client import ApiClient
from agilicus_api.exceptions import (
    ApiTypeError,
    ApiValueError
)


class MetricsApi(object):
    """NOTE: This class is auto generated by OpenAPI Generator
    Ref: https://openapi-generator.tech

    Do not edit the class manually.
    """

    def __init__(self, api_client=None):
        if api_client is None:
            api_client = ApiClient()
        self.api_client = api_client

    def list_active_users(self, org_id, **kwargs):  # noqa: E501
        """View number of active users  # noqa: E501

        View number of active users  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.list_active_users(org_id, async_req=True)
        >>> result = thread.get()

        :param async_req bool: execute request asynchronously
        :param str org_id: Organisation Unique identifier (required)
        :param str dt_from: Search criteria from when the query happened. * Inclusive. * In UTC. * Supports human-friendly values such as \"now\", \"today\", \"now-1day\". 
        :param str dt_to: Search criteria until when the query happened. * Exclusive. * In UTC. * Supports human-friendly values such as \"now\", \"today\", \"now-1day\". 
        :param str app_id: Application unique identifier
        :param str sub_org_id: Sub Organisation Unique identifier
        :param str app_name: Application Name
        :param str organisation: Organisation Name
        :param int interval: The size of the time intervals in seconds
        :param str resource_type: The type of resource to query for
        :param str resource_name: The name of the resource to query for
        :param str resource_id: The id of the resource to query for
        :param _preload_content: if False, the urllib3.HTTPResponse object will
                                 be returned without reading/decoding response
                                 data. Default is True.
        :param _request_timeout: timeout setting for this request. If one
                                 number provided, it will be total request
                                 timeout. It can also be a pair (tuple) of
                                 (connection, read) timeouts.
        :return: ListActiveUsersResponse
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        return self.list_active_users_with_http_info(org_id, **kwargs)  # noqa: E501

    def list_active_users_with_http_info(self, org_id, **kwargs):  # noqa: E501
        """View number of active users  # noqa: E501

        View number of active users  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.list_active_users_with_http_info(org_id, async_req=True)
        >>> result = thread.get()

        :param async_req bool: execute request asynchronously
        :param str org_id: Organisation Unique identifier (required)
        :param str dt_from: Search criteria from when the query happened. * Inclusive. * In UTC. * Supports human-friendly values such as \"now\", \"today\", \"now-1day\". 
        :param str dt_to: Search criteria until when the query happened. * Exclusive. * In UTC. * Supports human-friendly values such as \"now\", \"today\", \"now-1day\". 
        :param str app_id: Application unique identifier
        :param str sub_org_id: Sub Organisation Unique identifier
        :param str app_name: Application Name
        :param str organisation: Organisation Name
        :param int interval: The size of the time intervals in seconds
        :param str resource_type: The type of resource to query for
        :param str resource_name: The name of the resource to query for
        :param str resource_id: The id of the resource to query for
        :param _return_http_data_only: response data without head status code
                                       and headers
        :param _preload_content: if False, the urllib3.HTTPResponse object will
                                 be returned without reading/decoding response
                                 data. Default is True.
        :param _request_timeout: timeout setting for this request. If one
                                 number provided, it will be total request
                                 timeout. It can also be a pair (tuple) of
                                 (connection, read) timeouts.
        :return: tuple(ListActiveUsersResponse, status_code(int), headers(HTTPHeaderDict))
                 If the method is called asynchronously,
                 returns the request thread.
        """

        local_var_params = locals()

        all_params = ['org_id', 'dt_from', 'dt_to', 'app_id', 'sub_org_id', 'app_name', 'organisation', 'interval', 'resource_type', 'resource_name', 'resource_id']  # noqa: E501
        all_params.append('async_req')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

        for key, val in six.iteritems(local_var_params['kwargs']):
            if key not in all_params:
                raise ApiTypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method list_active_users" % key
                )
            local_var_params[key] = val
        del local_var_params['kwargs']
        # verify the required parameter 'org_id' is set
        if self.api_client.client_side_validation and ('org_id' not in local_var_params or  # noqa: E501
                                                        local_var_params['org_id'] is None):  # noqa: E501
            raise ApiValueError("Missing the required parameter `org_id` when calling `list_active_users`")  # noqa: E501

        if self.api_client.client_side_validation and 'app_id' in local_var_params and not re.search(r'^[a-zA-Z0-9-]+$', local_var_params['app_id']):  # noqa: E501
            raise ApiValueError("Invalid value for parameter `app_id` when calling `list_active_users`, must conform to the pattern `/^[a-zA-Z0-9-]+$/`")  # noqa: E501
        if self.api_client.client_side_validation and ('app_name' in local_var_params and  # noqa: E501
                                                        len(local_var_params['app_name']) > 63):  # noqa: E501
            raise ApiValueError("Invalid value for parameter `app_name` when calling `list_active_users`, length must be less than or equal to `63`")  # noqa: E501
        if self.api_client.client_side_validation and ('app_name' in local_var_params and  # noqa: E501
                                                        len(local_var_params['app_name']) < 1):  # noqa: E501
            raise ApiValueError("Invalid value for parameter `app_name` when calling `list_active_users`, length must be greater than or equal to `1`")  # noqa: E501
        if self.api_client.client_side_validation and 'app_name' in local_var_params and not re.search(r'^[a-zA-Z0-9-:]+$', local_var_params['app_name']):  # noqa: E501
            raise ApiValueError("Invalid value for parameter `app_name` when calling `list_active_users`, must conform to the pattern `/^[a-zA-Z0-9-:]+$/`")  # noqa: E501
        if self.api_client.client_side_validation and 'interval' in local_var_params and local_var_params['interval'] < 1:  # noqa: E501
            raise ApiValueError("Invalid value for parameter `interval` when calling `list_active_users`, must be a value greater than or equal to `1`")  # noqa: E501
        if self.api_client.client_side_validation and ('resource_name' in local_var_params and  # noqa: E501
                                                        len(local_var_params['resource_name']) > 100):  # noqa: E501
            raise ApiValueError("Invalid value for parameter `resource_name` when calling `list_active_users`, length must be less than or equal to `100`")  # noqa: E501
        if self.api_client.client_side_validation and 'resource_name' in local_var_params and not re.search(r'^[a-zA-Z0-9-_.:]+$', local_var_params['resource_name']):  # noqa: E501
            raise ApiValueError("Invalid value for parameter `resource_name` when calling `list_active_users`, must conform to the pattern `/^[a-zA-Z0-9-_.:]+$/`")  # noqa: E501
        collection_formats = {}

        path_params = {}
        if 'org_id' in local_var_params:
            path_params['org_id'] = local_var_params['org_id']  # noqa: E501

        query_params = []
        if 'dt_from' in local_var_params and local_var_params['dt_from'] is not None:  # noqa: E501
            query_params.append(('dt_from', local_var_params['dt_from']))  # noqa: E501
        if 'dt_to' in local_var_params and local_var_params['dt_to'] is not None:  # noqa: E501
            query_params.append(('dt_to', local_var_params['dt_to']))  # noqa: E501
        if 'app_id' in local_var_params and local_var_params['app_id'] is not None:  # noqa: E501
            query_params.append(('app_id', local_var_params['app_id']))  # noqa: E501
        if 'sub_org_id' in local_var_params and local_var_params['sub_org_id'] is not None:  # noqa: E501
            query_params.append(('sub_org_id', local_var_params['sub_org_id']))  # noqa: E501
        if 'app_name' in local_var_params and local_var_params['app_name'] is not None:  # noqa: E501
            query_params.append(('app_name', local_var_params['app_name']))  # noqa: E501
        if 'organisation' in local_var_params and local_var_params['organisation'] is not None:  # noqa: E501
            query_params.append(('organisation', local_var_params['organisation']))  # noqa: E501
        if 'interval' in local_var_params and local_var_params['interval'] is not None:  # noqa: E501
            query_params.append(('interval', local_var_params['interval']))  # noqa: E501
        if 'resource_type' in local_var_params and local_var_params['resource_type'] is not None:  # noqa: E501
            query_params.append(('resource_type', local_var_params['resource_type']))  # noqa: E501
        if 'resource_name' in local_var_params and local_var_params['resource_name'] is not None:  # noqa: E501
            query_params.append(('resource_name', local_var_params['resource_name']))  # noqa: E501
        if 'resource_id' in local_var_params and local_var_params['resource_id'] is not None:  # noqa: E501
            query_params.append(('resource_id', local_var_params['resource_id']))  # 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

        # Authentication setting
        auth_settings = ['token-valid']  # noqa: E501

        return self.api_client.call_api(
            '/v1/metrics/{org_id}/active_users', 'GET',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='ListActiveUsersResponse',  # noqa: E501
            auth_settings=auth_settings,
            async_req=local_var_params.get('async_req'),
            _return_http_data_only=local_var_params.get('_return_http_data_only'),  # noqa: E501
            _preload_content=local_var_params.get('_preload_content', True),
            _request_timeout=local_var_params.get('_request_timeout'),
            collection_formats=collection_formats)

    def list_top_users(self, org_id, **kwargs):  # noqa: E501
        """View top users  # noqa: E501

        View top users  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.list_top_users(org_id, async_req=True)
        >>> result = thread.get()

        :param async_req bool: execute request asynchronously
        :param str org_id: Organisation Unique identifier (required)
        :param str dt_from: Search criteria from when the query happened. * Inclusive. * In UTC. * Supports human-friendly values such as \"now\", \"today\", \"now-1day\". 
        :param str dt_to: Search criteria until when the query happened. * Exclusive. * In UTC. * Supports human-friendly values such as \"now\", \"today\", \"now-1day\". 
        :param str app_id: Application unique identifier
        :param str sub_org_id: Sub Organisation Unique identifier
        :param str app_name: Application Name
        :param str organisation: Organisation Name
        :param int interval: The size of the time intervals in seconds
        :param int limit: limit the number of top users in the response
        :param str resource_type: The type of resource to query for
        :param str resource_name: The name of the resource to query for
        :param str resource_id: The id of the resource to query for
        :param _preload_content: if False, the urllib3.HTTPResponse object will
                                 be returned without reading/decoding response
                                 data. Default is True.
        :param _request_timeout: timeout setting for this request. If one
                                 number provided, it will be total request
                                 timeout. It can also be a pair (tuple) of
                                 (connection, read) timeouts.
        :return: ListTopUsersResponse
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        return self.list_top_users_with_http_info(org_id, **kwargs)  # noqa: E501

    def list_top_users_with_http_info(self, org_id, **kwargs):  # noqa: E501
        """View top users  # noqa: E501

        View top users  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.list_top_users_with_http_info(org_id, async_req=True)
        >>> result = thread.get()

        :param async_req bool: execute request asynchronously
        :param str org_id: Organisation Unique identifier (required)
        :param str dt_from: Search criteria from when the query happened. * Inclusive. * In UTC. * Supports human-friendly values such as \"now\", \"today\", \"now-1day\". 
        :param str dt_to: Search criteria until when the query happened. * Exclusive. * In UTC. * Supports human-friendly values such as \"now\", \"today\", \"now-1day\". 
        :param str app_id: Application unique identifier
        :param str sub_org_id: Sub Organisation Unique identifier
        :param str app_name: Application Name
        :param str organisation: Organisation Name
        :param int interval: The size of the time intervals in seconds
        :param int limit: limit the number of top users in the response
        :param str resource_type: The type of resource to query for
        :param str resource_name: The name of the resource to query for
        :param str resource_id: The id of the resource to query for
        :param _return_http_data_only: response data without head status code
                                       and headers
        :param _preload_content: if False, the urllib3.HTTPResponse object will
                                 be returned without reading/decoding response
                                 data. Default is True.
        :param _request_timeout: timeout setting for this request. If one
                                 number provided, it will be total request
                                 timeout. It can also be a pair (tuple) of
                                 (connection, read) timeouts.
        :return: tuple(ListTopUsersResponse, status_code(int), headers(HTTPHeaderDict))
                 If the method is called asynchronously,
                 returns the request thread.
        """

        local_var_params = locals()

        all_params = ['org_id', 'dt_from', 'dt_to', 'app_id', 'sub_org_id', 'app_name', 'organisation', 'interval', 'limit', 'resource_type', 'resource_name', 'resource_id']  # noqa: E501
        all_params.append('async_req')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

        for key, val in six.iteritems(local_var_params['kwargs']):
            if key not in all_params:
                raise ApiTypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method list_top_users" % key
                )
            local_var_params[key] = val
        del local_var_params['kwargs']
        # verify the required parameter 'org_id' is set
        if self.api_client.client_side_validation and ('org_id' not in local_var_params or  # noqa: E501
                                                        local_var_params['org_id'] is None):  # noqa: E501
            raise ApiValueError("Missing the required parameter `org_id` when calling `list_top_users`")  # noqa: E501

        if self.api_client.client_side_validation and 'app_id' in local_var_params and not re.search(r'^[a-zA-Z0-9-]+$', local_var_params['app_id']):  # noqa: E501
            raise ApiValueError("Invalid value for parameter `app_id` when calling `list_top_users`, must conform to the pattern `/^[a-zA-Z0-9-]+$/`")  # noqa: E501
        if self.api_client.client_side_validation and ('app_name' in local_var_params and  # noqa: E501
                                                        len(local_var_params['app_name']) > 63):  # noqa: E501
            raise ApiValueError("Invalid value for parameter `app_name` when calling `list_top_users`, length must be less than or equal to `63`")  # noqa: E501
        if self.api_client.client_side_validation and ('app_name' in local_var_params and  # noqa: E501
                                                        len(local_var_params['app_name']) < 1):  # noqa: E501
            raise ApiValueError("Invalid value for parameter `app_name` when calling `list_top_users`, length must be greater than or equal to `1`")  # noqa: E501
        if self.api_client.client_side_validation and 'app_name' in local_var_params and not re.search(r'^[a-zA-Z0-9-:]+$', local_var_params['app_name']):  # noqa: E501
            raise ApiValueError("Invalid value for parameter `app_name` when calling `list_top_users`, must conform to the pattern `/^[a-zA-Z0-9-:]+$/`")  # noqa: E501
        if self.api_client.client_side_validation and 'interval' in local_var_params and local_var_params['interval'] < 1:  # noqa: E501
            raise ApiValueError("Invalid value for parameter `interval` when calling `list_top_users`, must be a value greater than or equal to `1`")  # noqa: E501
        if self.api_client.client_side_validation and 'limit' in local_var_params and local_var_params['limit'] > 500:  # noqa: E501
            raise ApiValueError("Invalid value for parameter `limit` when calling `list_top_users`, must be a value less than or equal to `500`")  # noqa: E501
        if self.api_client.client_side_validation and 'limit' in local_var_params and local_var_params['limit'] < 1:  # noqa: E501
            raise ApiValueError("Invalid value for parameter `limit` when calling `list_top_users`, must be a value greater than or equal to `1`")  # noqa: E501
        if self.api_client.client_side_validation and ('resource_name' in local_var_params and  # noqa: E501
                                                        len(local_var_params['resource_name']) > 100):  # noqa: E501
            raise ApiValueError("Invalid value for parameter `resource_name` when calling `list_top_users`, length must be less than or equal to `100`")  # noqa: E501
        if self.api_client.client_side_validation and 'resource_name' in local_var_params and not re.search(r'^[a-zA-Z0-9-_.:]+$', local_var_params['resource_name']):  # noqa: E501
            raise ApiValueError("Invalid value for parameter `resource_name` when calling `list_top_users`, must conform to the pattern `/^[a-zA-Z0-9-_.:]+$/`")  # noqa: E501
        collection_formats = {}

        path_params = {}
        if 'org_id' in local_var_params:
            path_params['org_id'] = local_var_params['org_id']  # noqa: E501

        query_params = []
        if 'dt_from' in local_var_params and local_var_params['dt_from'] is not None:  # noqa: E501
            query_params.append(('dt_from', local_var_params['dt_from']))  # noqa: E501
        if 'dt_to' in local_var_params and local_var_params['dt_to'] is not None:  # noqa: E501
            query_params.append(('dt_to', local_var_params['dt_to']))  # noqa: E501
        if 'app_id' in local_var_params and local_var_params['app_id'] is not None:  # noqa: E501
            query_params.append(('app_id', local_var_params['app_id']))  # noqa: E501
        if 'sub_org_id' in local_var_params and local_var_params['sub_org_id'] is not None:  # noqa: E501
            query_params.append(('sub_org_id', local_var_params['sub_org_id']))  # noqa: E501
        if 'app_name' in local_var_params and local_var_params['app_name'] is not None:  # noqa: E501
            query_params.append(('app_name', local_var_params['app_name']))  # noqa: E501
        if 'organisation' in local_var_params and local_var_params['organisation'] is not None:  # noqa: E501
            query_params.append(('organisation', local_var_params['organisation']))  # noqa: E501
        if 'interval' in local_var_params and local_var_params['interval'] is not None:  # noqa: E501
            query_params.append(('interval', local_var_params['interval']))  # noqa: E501
        if 'limit' in local_var_params and local_var_params['limit'] is not None:  # noqa: E501
            query_params.append(('limit', local_var_params['limit']))  # noqa: E501
        if 'resource_type' in local_var_params and local_var_params['resource_type'] is not None:  # noqa: E501
            query_params.append(('resource_type', local_var_params['resource_type']))  # noqa: E501
        if 'resource_name' in local_var_params and local_var_params['resource_name'] is not None:  # noqa: E501
            query_params.append(('resource_name', local_var_params['resource_name']))  # noqa: E501
        if 'resource_id' in local_var_params and local_var_params['resource_id'] is not None:  # noqa: E501
            query_params.append(('resource_id', local_var_params['resource_id']))  # 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

        # Authentication setting
        auth_settings = ['token-valid']  # noqa: E501

        return self.api_client.call_api(
            '/v1/metrics/{org_id}/top_users', 'GET',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='ListTopUsersResponse',  # noqa: E501
            auth_settings=auth_settings,
            async_req=local_var_params.get('async_req'),
            _return_http_data_only=local_var_params.get('_return_http_data_only'),  # noqa: E501
            _preload_content=local_var_params.get('_preload_content', True),
            _request_timeout=local_var_params.get('_request_timeout'),
            collection_formats=collection_formats)
