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

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


    def get_organization_licenses(self,
                                  organization_id,
                                  per_page=None,
                                  starting_after=None,
                                  ending_before=None,
                                  device_serial=None,
                                  network_id=None,
                                  state=None):
        """Does a GET request to /organizations/{organizationId}/licenses.

        List the licenses for 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.
            device_serial (string, optional): Filter the licenses to those
                assigned to a particular device
            network_id (string, optional): Filter the licenses to those
                assigned in a particular network
            state (StateEnum, optional): Filter the licenses to those in a
                particular state. Can be one of 'active', 'expired',
                'expiring', 'unused', 'unusedActive' or 'recentlyQueued'

        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}/licenses'
        _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,
            'deviceSerial': device_serial,
            'networkId': network_id,
            'state': state
        }
        _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_assign_organization_licenses_seats(self,
                                                  organization_id,
                                                  assign_organization_licenses_seats):
        """Does a POST request to /organizations/{organizationId}/licenses/assignSeats.

        Assign SM seats to a network. This will increase the managed SM device
        limit of the network

        Args:
            organization_id (string): TODO: type description here. Example: 
            assign_organization_licenses_seats
                (AssignOrganizationLicensesSeats): 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 = '/organizations/{organizationId}/licenses/assignSeats'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, { 
            'organizationId': organization_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(assign_organization_licenses_seats))
        CustomHeaderAuth.apply(_request)
        _context = self.execute_request(_request)
        self.validate_response(_context)

        # Return appropriate type
        return _context.response.raw_body

    def create_move_organization_licenses(self,
                                          organization_id,
                                          move_organization_licenses):
        """Does a POST request to /organizations/{organizationId}/licenses/move.

        Move licenses to another organization. This will also move any devices
        that the licenses are assigned to

        Args:
            organization_id (string): TODO: type description here. Example: 
            move_organization_licenses (MoveOrganizationLicenses): 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 = '/organizations/{organizationId}/licenses/move'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, { 
            'organizationId': organization_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(move_organization_licenses))
        CustomHeaderAuth.apply(_request)
        _context = self.execute_request(_request)
        self.validate_response(_context)

        # Return appropriate type
        return _context.response.raw_body

    def create_move_organization_licenses_seats(self,
                                                organization_id,
                                                move_organization_licenses_seats):
        """Does a POST request to /organizations/{organizationId}/licenses/moveSeats.

        Move SM seats to another organization

        Args:
            organization_id (string): TODO: type description here. Example: 
            move_organization_licenses_seats (MoveOrganizationLicensesSeats):
                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 = '/organizations/{organizationId}/licenses/moveSeats'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, { 
            'organizationId': organization_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(move_organization_licenses_seats))
        CustomHeaderAuth.apply(_request)
        _context = self.execute_request(_request)
        self.validate_response(_context)

        # Return appropriate type
        return _context.response.raw_body

    def create_renew_organization_licenses_seats(self,
                                                 organization_id,
                                                 renew_organization_licenses_seats):
        """Does a POST request to /organizations/{organizationId}/licenses/renewSeats.

        Renew SM seats of a license. This will extend the license expiration
        date of managed SM devices covered by this license

        Args:
            organization_id (string): TODO: type description here. Example: 
            renew_organization_licenses_seats
                (RenewOrganizationLicensesSeats): 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 = '/organizations/{organizationId}/licenses/renewSeats'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, { 
            'organizationId': organization_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(renew_organization_licenses_seats))
        CustomHeaderAuth.apply(_request)
        _context = self.execute_request(_request)
        self.validate_response(_context)

        # Return appropriate type
        return _context.response.raw_body

    def get_organization_license(self,
                                 organization_id,
                                 license_id):
        """Does a GET request to /organizations/{organizationId}/licenses/{licenseId}.

        Display a license

        Args:
            organization_id (string): TODO: type description here. Example: 
            license_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 = '/organizations/{organizationId}/licenses/{licenseId}'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, { 
            'organizationId': organization_id,
            'licenseId': license_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_organization_license(self,
                                    organization_id,
                                    license_id,
                                    update_organization_license=None):
        """Does a PUT request to /organizations/{organizationId}/licenses/{licenseId}.

        Update a license

        Args:
            organization_id (string): TODO: type description here. Example: 
            license_id (string): TODO: type description here. Example: 
            update_organization_license (UpdateOrganizationLicense, 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 = '/organizations/{organizationId}/licenses/{licenseId}'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, { 
            'organizationId': organization_id,
            'licenseId': license_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_organization_license))
        CustomHeaderAuth.apply(_request)
        _context = self.execute_request(_request)
        self.validate_response(_context)

        # Return appropriate type
        return _context.response.raw_body
