# -*- 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 DevicesController(BaseController):

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


    def get_network_devices(self,
                            network_id):
        """Does a GET request to /networks/{networkId}/devices.

        List the devices in a network

        Args:
            network_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}/devices'
        _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 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_claim_network_devices(self,
                                     network_id,
                                     claim_network_devices):
        """Does a POST request to /networks/{networkId}/devices/claim.

        Claim a device into a network

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

        Returns:
            void: 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}/devices/claim'
        _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(claim_network_devices))
        CustomHeaderAuth.apply(_request)
        _context = self.execute_request(_request)
        self.validate_response(_context)

    def get_network_device(self,
                           network_id,
                           serial):
        """Does a GET request to /networks/{networkId}/devices/{serial}.

        Return a single device

        Args:
            network_id (string): TODO: type description here. Example: 
            serial (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}/devices/{serial}'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, { 
            'networkId': network_id,
            'serial': serial
        })
        _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_device(self,
                              network_id,
                              serial,
                              update_network_device=None):
        """Does a PUT request to /networks/{networkId}/devices/{serial}.

        Update the attributes of a device

        Args:
            network_id (string): TODO: type description here. Example: 
            serial (string): TODO: type description here. Example: 
            update_network_device (UpdateNetworkDevice, 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}/devices/{serial}'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, { 
            'networkId': network_id,
            'serial': serial
        })
        _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_device))
        CustomHeaderAuth.apply(_request)
        _context = self.execute_request(_request)
        self.validate_response(_context)

        # Return appropriate type
        return _context.response.raw_body

    def create_blink_network_device_leds(self,
                                         network_id,
                                         serial,
                                         blink_network_device_leds=None):
        """Does a POST request to /networks/{networkId}/devices/{serial}/blinkLeds.

        Blink the LEDs on a device

        Args:
            network_id (string): TODO: type description here. Example: 
            serial (string): TODO: type description here. Example: 
            blink_network_device_leds (BlinkNetworkDeviceLeds, 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}/devices/{serial}/blinkLeds'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, { 
            'networkId': network_id,
            'serial': serial
        })
        _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(blink_network_device_leds))
        CustomHeaderAuth.apply(_request)
        _context = self.execute_request(_request)
        self.validate_response(_context)

        # Return appropriate type
        return _context.response.raw_body

    def get_network_device_lldp_cdp(self,
                                    network_id,
                                    serial,
                                    timespan=None):
        """Does a GET request to /networks/{networkId}/devices/{serial}/lldp_cdp.

        List LLDP and CDP information for a device

        Args:
            network_id (string): TODO: type description here. Example: 
            serial (string): TODO: type description here. Example: 
            timespan (int, optional): The timespan for which LLDP and CDP
                information will be fetched. Must be in seconds and less than
                or equal to a month (2592000 seconds). LLDP and CDP
                information is sent to the Meraki dashboard every 10 minutes.
                In instances where this LLDP and CDP information matches an
                existing entry in the Meraki dashboard, the data is updated
                once every two hours. Meraki recommends querying LLDP and CDP
                information at an interval slightly greater than two hours, to
                ensure that unchanged CDP / LLDP information can be queried
                consistently.

        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}/devices/{serial}/lldp_cdp'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, { 
            'networkId': network_id,
            'serial': serial
        })
        _query_builder = Configuration.base_uri
        _query_builder += _url_path
        _query_parameters = {
            '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_device_loss_and_latency_history(self,
                                                    network_id,
                                                    serial,
                                                    ip,
                                                    t_0=None,
                                                    t_1=None,
                                                    timespan=None,
                                                    resolution=None,
                                                    uplink=None):
        """Does a GET request to /networks/{networkId}/devices/{serial}/lossAndLatencyHistory.

        Get the uplink loss percentage and latency in milliseconds for a wired
        network device.

        Args:
            network_id (string): TODO: type description here. Example: 
            serial (string): TODO: type description here. Example: 
            ip (string): The destination IP used to obtain the requested
                stats. This is required.
            t_0 (string, optional): The beginning of the timespan for the
                data. The maximum lookback period is 365 days from today.
            t_1 (string, optional): The end of the timespan for the data. t1
                can be a maximum of 31 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 31 days. The default is 1 day.
            resolution (int, optional): The time resolution in seconds for
                returned data. The valid resolutions are: 60, 600, 3600,
                86400. The default is 60.
            uplink (UplinkEnum, optional): The WAN uplink used to obtain the
                requested stats. Valid uplinks are wan1, wan2, cellular. The
                default is wan1.

        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}/devices/{serial}/lossAndLatencyHistory'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, { 
            'networkId': network_id,
            'serial': serial
        })
        _query_builder = Configuration.base_uri
        _query_builder += _url_path
        _query_parameters = {
            'ip': ip,
            't0': t_0,
            't1': t_1,
            'timespan': timespan,
            'resolution': resolution,
            'uplink': uplink
        }
        _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_device_performance(self,
                                       network_id,
                                       serial):
        """Does a GET request to /networks/{networkId}/devices/{serial}/performance.

        Return the performance score for a single device. Only primary MX
        devices supported. If no data is available, a 204 error code is
        returned.

        Args:
            network_id (string): TODO: type description here. Example: 
            serial (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}/devices/{serial}/performance'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, { 
            'networkId': network_id,
            'serial': serial
        })
        _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 create_reboot_network_device(self,
                                     network_id,
                                     serial):
        """Does a POST request to /networks/{networkId}/devices/{serial}/reboot.

        Reboot a device

        Args:
            network_id (string): TODO: type description here. Example: 
            serial (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}/devices/{serial}/reboot'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, { 
            'networkId': network_id,
            'serial': serial
        })
        _query_builder = Configuration.base_uri
        _query_builder += _url_path
        _query_url = APIHelper.clean_url(_query_builder)

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

        # Return appropriate type
        return _context.response.raw_body

    def create_remove_network_device(self,
                                     network_id,
                                     serial):
        """Does a POST request to /networks/{networkId}/devices/{serial}/remove.

        Remove a single device

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

        Returns:
            void: 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}/devices/{serial}/remove'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, { 
            'networkId': network_id,
            'serial': serial
        })
        _query_builder = Configuration.base_uri
        _query_builder += _url_path
        _query_url = APIHelper.clean_url(_query_builder)

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

    def get_network_device_uplink(self,
                                  network_id,
                                  serial):
        """Does a GET request to /networks/{networkId}/devices/{serial}/uplink.

        Return the uplink information for a device.

        Args:
            network_id (string): TODO: type description here. Example: 
            serial (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}/devices/{serial}/uplink'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, { 
            'networkId': network_id,
            'serial': serial
        })
        _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_organization_devices(self,
                                 organization_id,
                                 per_page=None,
                                 starting_after=None,
                                 ending_before=None):
        """Does a GET request to /organizations/{organizationId}/devices.

        List the devices in an organization

        Args:
            organization_id (string): TODO: type description here. Example: 
            per_page (int, optional): The number of entries per page returned.
                Acceptable range is 3 - 1000. Default is 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 = '/organizations/{organizationId}/devices'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, { 
            'organizationId': organization_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
