# -*- coding: utf-8 -*-

"""
    test_meraki

    This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ).
"""

from test_meraki.api_helper import APIHelper
from test_meraki.configuration import Configuration
from test_meraki.controllers.base_controller import BaseController
from test_meraki.http.auth.custom_header_auth import CustomHeaderAuth

class ClientsController(BaseController):

    """A Controller to access Endpoints in the test_meraki API."""


    def get_device_clients(self,
                           serial,
                           t_0=None,
                           timespan=None):
        """Does a GET request to /devices/{serial}/clients.

        List the clients of a device, up to a maximum of a month ago. The
        usage of each client is returned in kilobytes. If the device is a
        switch, the switchport is returned; otherwise the switchport field is
        null.

        Args:
            serial (string): TODO: type description here. Example: 
            t_0 (string, optional): The beginning of the timespan for the
                data. The maximum lookback period is 31 days from today.
            timespan (float, optional): The timespan for which the information
                will be fetched. If specifying timespan, do not specify
                parameter t0. The value must be in seconds and be less than or
                equal to 31 days. The default is 1 day.

        Returns:
            object: Response from the API. Successful operation

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """

        # Prepare query URL
        _url_path = '/devices/{serial}/clients'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, { 
            'serial': serial
        })
        _query_builder = Configuration.base_uri
        _query_builder += _url_path
        _query_parameters = {
            't0': t_0,
            'timespan': timespan
        }
        _query_builder = APIHelper.append_url_with_query_parameters(_query_builder,
            _query_parameters, Configuration.array_serialization)
        _query_url = APIHelper.clean_url(_query_builder)

        # Prepare and execute request
        _request = self.http_client.get(_query_url)
        CustomHeaderAuth.apply(_request)
        _context = self.execute_request(_request)
        self.validate_response(_context)

        # Return appropriate type
        return _context.response.raw_body

    def get_network_clients(self,
                            network_id,
                            t_0=None,
                            timespan=None,
                            per_page=None,
                            starting_after=None,
                            ending_before=None):
        """Does a GET request to /networks/{networkId}/clients.

        List the clients that have used this network in the timespan

        Args:
            network_id (string): TODO: type description here. Example: 
            t_0 (string, optional): The beginning of the timespan for the
                data. The maximum lookback period is 31 days from today.
            timespan (float, optional): The timespan for which the information
                will be fetched. If specifying timespan, do not specify
                parameter t0. The value must be in seconds and be less than or
                equal to 31 days. The default is 1 day.
            per_page (int, optional): The number of entries per page returned.
                Acceptable range is 3 - 1000. Default is 10.
            starting_after (string, optional): A token used by the server to
                indicate the start of the page. Often this is a timestamp or
                an ID but it is not limited to those. This parameter should
                not be defined by client applications. The link for the first,
                last, prev, or next page in the HTTP Link header should define
                it.
            ending_before (string, optional): A token used by the server to
                indicate the end of the page. Often this is a timestamp or an
                ID but it is not limited to those. This parameter should not
                be defined by client applications. The link for the first,
                last, prev, or next page in the HTTP Link header should define
                it.

        Returns:
            object: Response from the API. Successful operation

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """

        # Prepare query URL
        _url_path = '/networks/{networkId}/clients'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, { 
            'networkId': network_id
        })
        _query_builder = Configuration.base_uri
        _query_builder += _url_path
        _query_parameters = {
            't0': t_0,
            'timespan': timespan,
            'perPage': per_page,
            'startingAfter': starting_after,
            'endingBefore': ending_before
        }
        _query_builder = APIHelper.append_url_with_query_parameters(_query_builder,
            _query_parameters, Configuration.array_serialization)
        _query_url = APIHelper.clean_url(_query_builder)

        # Prepare and execute request
        _request = self.http_client.get(_query_url)
        CustomHeaderAuth.apply(_request)
        _context = self.execute_request(_request)
        self.validate_response(_context)

        # Return appropriate type
        return _context.response.raw_body

    def create_provision_network_clients(self,
                                         network_id,
                                         provision_network_clients=None):
        """Does a POST request to /networks/{networkId}/clients/provision.

        Provisions a client with a name and policy. Clients can be provisioned
        before they associate to the network.

        Args:
            network_id (string): TODO: type description here. Example: 
            provision_network_clients (ProvisionNetworkClients, optional):
                TODO: type description here. Example: 

        Returns:
            object: Response from the API. Successful operation

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """

        # Prepare query URL
        _url_path = '/networks/{networkId}/clients/provision'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, { 
            'networkId': network_id
        })
        _query_builder = Configuration.base_uri
        _query_builder += _url_path
        _query_url = APIHelper.clean_url(_query_builder)

        # Prepare headers
        _headers = {
            'content-type': 'application/json; charset=utf-8'
        }

        # Prepare and execute request
        _request = self.http_client.post(_query_url, headers=_headers, parameters=APIHelper.json_serialize(provision_network_clients))
        CustomHeaderAuth.apply(_request)
        _context = self.execute_request(_request)
        self.validate_response(_context)

        # Return appropriate type
        return _context.response.raw_body

    def get_network_client(self,
                           network_id,
                           client_id):
        """Does a GET request to /networks/{networkId}/clients/{clientId}.

        Return the client associated with the given identifier. Clients can be
        identified by a client key or either the MAC or IP depending on
        whether the network uses Track-by-IP.

        Args:
            network_id (string): TODO: type description here. Example: 
            client_id (string): TODO: type description here. Example: 

        Returns:
            object: Response from the API. Successful operation

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """

        # Prepare query URL
        _url_path = '/networks/{networkId}/clients/{clientId}'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, { 
            'networkId': network_id,
            'clientId': client_id
        })
        _query_builder = Configuration.base_uri
        _query_builder += _url_path
        _query_url = APIHelper.clean_url(_query_builder)

        # Prepare and execute request
        _request = self.http_client.get(_query_url)
        CustomHeaderAuth.apply(_request)
        _context = self.execute_request(_request)
        self.validate_response(_context)

        # Return appropriate type
        return _context.response.raw_body

    def get_network_client_events(self,
                                  network_id,
                                  client_id,
                                  per_page=None,
                                  starting_after=None,
                                  ending_before=None):
        """Does a GET request to /networks/{networkId}/clients/{clientId}/events.

        Return the events associated with this client. Clients can be
        identified by a client key or either the MAC or IP depending on
        whether the network uses Track-by-IP.

        Args:
            network_id (string): TODO: type description here. Example: 
            client_id (string): TODO: type description here. Example: 
            per_page (int, optional): The number of entries per page returned.
                Acceptable range is 3 - 100. Default is 100.
            starting_after (string, optional): A token used by the server to
                indicate the start of the page. Often this is a timestamp or
                an ID but it is not limited to those. This parameter should
                not be defined by client applications. The link for the first,
                last, prev, or next page in the HTTP Link header should define
                it.
            ending_before (string, optional): A token used by the server to
                indicate the end of the page. Often this is a timestamp or an
                ID but it is not limited to those. This parameter should not
                be defined by client applications. The link for the first,
                last, prev, or next page in the HTTP Link header should define
                it.

        Returns:
            object: Response from the API. Successful operation

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """

        # Prepare query URL
        _url_path = '/networks/{networkId}/clients/{clientId}/events'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, { 
            'networkId': network_id,
            'clientId': client_id
        })
        _query_builder = Configuration.base_uri
        _query_builder += _url_path
        _query_parameters = {
            'perPage': per_page,
            'startingAfter': starting_after,
            'endingBefore': ending_before
        }
        _query_builder = APIHelper.append_url_with_query_parameters(_query_builder,
            _query_parameters, Configuration.array_serialization)
        _query_url = APIHelper.clean_url(_query_builder)

        # Prepare and execute request
        _request = self.http_client.get(_query_url)
        CustomHeaderAuth.apply(_request)
        _context = self.execute_request(_request)
        self.validate_response(_context)

        # Return appropriate type
        return _context.response.raw_body

    def get_network_client_latency_history(self,
                                           network_id,
                                           client_id,
                                           t_0=None,
                                           t_1=None,
                                           timespan=None,
                                           resolution=None):
        """Does a GET request to /networks/{networkId}/clients/{clientId}/latencyHistory.

        Return the latency history for a client. Clients can be identified by
        a client key or either the MAC or IP depending on whether the network
        uses Track-by-IP. The latency data is from a sample of 2% of packets
        and is grouped into 4 traffic categories: background, best effort,
        video, voice. Within these categories the sampled packet counters are
        bucketed by latency in milliseconds.

        Args:
            network_id (string): TODO: type description here. Example: 
            client_id (string): TODO: type description here. Example: 
            t_0 (string, optional): The beginning of the timespan for the
                data. The maximum lookback period is 791 days from today.
            t_1 (string, optional): The end of the timespan for the data. t1
                can be a maximum of 791 days after t0.
            timespan (float, optional): The timespan for which the information
                will be fetched. If specifying timespan, do not specify
                parameters t0 and t1. The value must be in seconds and be less
                than or equal to 791 days. The default is 1 day.
            resolution (int, optional): The time resolution in seconds for
                returned data. The valid resolutions are: 86400. The default
                is 86400.

        Returns:
            object: Response from the API. Successful operation

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """

        # Prepare query URL
        _url_path = '/networks/{networkId}/clients/{clientId}/latencyHistory'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, { 
            'networkId': network_id,
            'clientId': client_id
        })
        _query_builder = Configuration.base_uri
        _query_builder += _url_path
        _query_parameters = {
            't0': t_0,
            't1': t_1,
            'timespan': timespan,
            'resolution': resolution
        }
        _query_builder = APIHelper.append_url_with_query_parameters(_query_builder,
            _query_parameters, Configuration.array_serialization)
        _query_url = APIHelper.clean_url(_query_builder)

        # Prepare and execute request
        _request = self.http_client.get(_query_url)
        CustomHeaderAuth.apply(_request)
        _context = self.execute_request(_request)
        self.validate_response(_context)

        # Return appropriate type
        return _context.response.raw_body

    def get_network_client_policy(self,
                                  network_id,
                                  client_id):
        """Does a GET request to /networks/{networkId}/clients/{clientId}/policy.

        Return the policy assigned to a client on the network. Clients can be
        identified by a client key or either the MAC or IP depending on
        whether the network uses Track-by-IP.

        Args:
            network_id (string): TODO: type description here. Example: 
            client_id (string): TODO: type description here. Example: 

        Returns:
            object: Response from the API. Successful operation

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """

        # Prepare query URL
        _url_path = '/networks/{networkId}/clients/{clientId}/policy'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, { 
            'networkId': network_id,
            'clientId': client_id
        })
        _query_builder = Configuration.base_uri
        _query_builder += _url_path
        _query_url = APIHelper.clean_url(_query_builder)

        # Prepare and execute request
        _request = self.http_client.get(_query_url)
        CustomHeaderAuth.apply(_request)
        _context = self.execute_request(_request)
        self.validate_response(_context)

        # Return appropriate type
        return _context.response.raw_body

    def update_network_client_policy(self,
                                     network_id,
                                     client_id,
                                     update_network_client_policy=None):
        """Does a PUT request to /networks/{networkId}/clients/{clientId}/policy.

        Update the policy assigned to a client on the network. Clients can be
        identified by a client key or either the MAC or IP depending on
        whether the network uses Track-by-IP.

        Args:
            network_id (string): TODO: type description here. Example: 
            client_id (string): TODO: type description here. Example: 
            update_network_client_policy (UpdateNetworkClientPolicy,
                optional): TODO: type description here. Example: 

        Returns:
            object: Response from the API. Successful operation

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """

        # Prepare query URL
        _url_path = '/networks/{networkId}/clients/{clientId}/policy'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, { 
            'networkId': network_id,
            'clientId': client_id
        })
        _query_builder = Configuration.base_uri
        _query_builder += _url_path
        _query_url = APIHelper.clean_url(_query_builder)

        # Prepare headers
        _headers = {
            'content-type': 'application/json; charset=utf-8'
        }

        # Prepare and execute request
        _request = self.http_client.put(_query_url, headers=_headers, parameters=APIHelper.json_serialize(update_network_client_policy))
        CustomHeaderAuth.apply(_request)
        _context = self.execute_request(_request)
        self.validate_response(_context)

        # Return appropriate type
        return _context.response.raw_body

    def get_network_client_splash_authorization_status(self,
                                                       network_id,
                                                       client_id):
        """Does a GET request to /networks/{networkId}/clients/{clientId}/splashAuthorizationStatus.

        Return the splash authorization for a client, for each SSID they've
        associated with through splash. Only enabled SSIDs with Click-through
        splash enabled will be included. Clients can be identified by a client
        key or either the MAC or IP depending on whether the network uses
        Track-by-IP.

        Args:
            network_id (string): TODO: type description here. Example: 
            client_id (string): TODO: type description here. Example: 

        Returns:
            object: Response from the API. Successful operation

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """

        # Prepare query URL
        _url_path = '/networks/{networkId}/clients/{clientId}/splashAuthorizationStatus'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, { 
            'networkId': network_id,
            'clientId': client_id
        })
        _query_builder = Configuration.base_uri
        _query_builder += _url_path
        _query_url = APIHelper.clean_url(_query_builder)

        # Prepare and execute request
        _request = self.http_client.get(_query_url)
        CustomHeaderAuth.apply(_request)
        _context = self.execute_request(_request)
        self.validate_response(_context)

        # Return appropriate type
        return _context.response.raw_body

    def update_network_client_splash_authorization_status(self,
                                                          network_id,
                                                          client_id,
                                                          update_network_client_splash_authorization_status=None):
        """Does a PUT request to /networks/{networkId}/clients/{clientId}/splashAuthorizationStatus.

        Update a client's splash authorization. Clients can be identified by a
        client key or either the MAC or IP depending on whether the network
        uses Track-by-IP.

        Args:
            network_id (string): TODO: type description here. Example: 
            client_id (string): TODO: type description here. Example: 
            update_network_client_splash_authorization_status
                (UpdateNetworkClientSplashAuthorizationStatus, optional):
                TODO: type description here. Example: 

        Returns:
            object: Response from the API. Successful operation

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """

        # Prepare query URL
        _url_path = '/networks/{networkId}/clients/{clientId}/splashAuthorizationStatus'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, { 
            'networkId': network_id,
            'clientId': client_id
        })
        _query_builder = Configuration.base_uri
        _query_builder += _url_path
        _query_url = APIHelper.clean_url(_query_builder)

        # Prepare headers
        _headers = {
            'content-type': 'application/json; charset=utf-8'
        }

        # Prepare and execute request
        _request = self.http_client.put(_query_url, headers=_headers, parameters=APIHelper.json_serialize(update_network_client_splash_authorization_status))
        CustomHeaderAuth.apply(_request)
        _context = self.execute_request(_request)
        self.validate_response(_context)

        # Return appropriate type
        return _context.response.raw_body

    def get_network_client_traffic_history(self,
                                           network_id,
                                           client_id,
                                           per_page=None,
                                           starting_after=None,
                                           ending_before=None):
        """Does a GET request to /networks/{networkId}/clients/{clientId}/trafficHistory.

        Return the client's network traffic data over time. Usage data is in
        kilobytes. This endpoint requires detailed traffic analysis to be
        enabled on the Network-wide > General page. Clients can be identified
        by a client key or either the MAC or IP depending on whether the
        network uses Track-by-IP.

        Args:
            network_id (string): TODO: type description here. Example: 
            client_id (string): TODO: type description here. Example: 
            per_page (int, optional): The number of entries per page returned.
                Acceptable range is 3 - 1000.
            starting_after (string, optional): A token used by the server to
                indicate the start of the page. Often this is a timestamp or
                an ID but it is not limited to those. This parameter should
                not be defined by client applications. The link for the first,
                last, prev, or next page in the HTTP Link header should define
                it.
            ending_before (string, optional): A token used by the server to
                indicate the end of the page. Often this is a timestamp or an
                ID but it is not limited to those. This parameter should not
                be defined by client applications. The link for the first,
                last, prev, or next page in the HTTP Link header should define
                it.

        Returns:
            object: Response from the API. Successful operation

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """

        # Prepare query URL
        _url_path = '/networks/{networkId}/clients/{clientId}/trafficHistory'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, { 
            'networkId': network_id,
            'clientId': client_id
        })
        _query_builder = Configuration.base_uri
        _query_builder += _url_path
        _query_parameters = {
            'perPage': per_page,
            'startingAfter': starting_after,
            'endingBefore': ending_before
        }
        _query_builder = APIHelper.append_url_with_query_parameters(_query_builder,
            _query_parameters, Configuration.array_serialization)
        _query_url = APIHelper.clean_url(_query_builder)

        # Prepare and execute request
        _request = self.http_client.get(_query_url)
        CustomHeaderAuth.apply(_request)
        _context = self.execute_request(_request)
        self.validate_response(_context)

        # Return appropriate type
        return _context.response.raw_body

    def get_network_client_usage_history(self,
                                         network_id,
                                         client_id):
        """Does a GET request to /networks/{networkId}/clients/{clientId}/usageHistory.

        Return the client's daily usage history. Usage data is in kilobytes.
        Clients can be identified by a client key or either the MAC or IP
        depending on whether the network uses Track-by-IP.

        Args:
            network_id (string): TODO: type description here. Example: 
            client_id (string): TODO: type description here. Example: 

        Returns:
            object: Response from the API. Successful operation

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """

        # Prepare query URL
        _url_path = '/networks/{networkId}/clients/{clientId}/usageHistory'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, { 
            'networkId': network_id,
            'clientId': client_id
        })
        _query_builder = Configuration.base_uri
        _query_builder += _url_path
        _query_url = APIHelper.clean_url(_query_builder)

        # Prepare and execute request
        _request = self.http_client.get(_query_url)
        CustomHeaderAuth.apply(_request)
        _context = self.execute_request(_request)
        self.validate_response(_context)

        # Return appropriate type
        return _context.response.raw_body
