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

"""
ctddocumentation

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

from ctddocumentation.api_helper import APIHelper
from ctddocumentation.configuration import Server
from ctddocumentation.controllers.base_controller import BaseController
from apimatic_core.request_builder import RequestBuilder
from apimatic_core.response_handler import ResponseHandler
from apimatic_core.types.parameter import Parameter
from ctddocumentation.http.http_method_enum import HttpMethodEnum
from apimatic_core.authentication.multiple.single_auth import Single
from apimatic_core.authentication.multiple.and_auth_group import And
from apimatic_core.authentication.multiple.or_auth_group import Or
from ctddocumentation.models.get_license_details_response import GetLicenseDetailsResponse
from ctddocumentation.models.update_license_response import UpdateLicenseResponse


class LicenseController(BaseController):

    """A Controller to access Endpoints in the ctddocumentation API."""
    def __init__(self, config):
        super(LicenseController, self).__init__(config)

    def get_license_details(self,
                            site_id):
        """Does a GET request to /ranger/license/{site_id}.

        Admin users can get the current license details

        Args:
            site_id (int): On which site to operate

        Returns:
            GetLicenseDetailsResponse: 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.

        """

        return super().new_api_call_builder.request(
            RequestBuilder().server(Server.DEFAULT)
            .path('/ranger/license/{site_id}')
            .http_method(HttpMethodEnum.GET)
            .template_param(Parameter()
                            .key('site_id')
                            .value(site_id)
                            .should_encode(True))
            .header_param(Parameter()
                          .key('accept')
                          .value('application/json'))
            .auth(Single('global'))
        ).response(
            ResponseHandler()
            .deserializer(APIHelper.json_deserialize)
            .deserialize_into(GetLicenseDetailsResponse.from_dictionary)
        ).execute()

    def add_license(self,
                    site_id,
                    body):
        """Does a POST request to /ranger/license/{site_id}.

        Add License

        Args:
            site_id (int): On which site to operate
            body (LicenseRequest): Set license

        Returns:
            UpdateLicenseResponse: 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.

        """

        return super().new_api_call_builder.request(
            RequestBuilder().server(Server.DEFAULT)
            .path('/ranger/license/{site_id}')
            .http_method(HttpMethodEnum.POST)
            .template_param(Parameter()
                            .key('site_id')
                            .value(site_id)
                            .should_encode(True))
            .header_param(Parameter()
                          .key('Content-Type')
                          .value('application/json'))
            .body_param(Parameter()
                        .value(body))
            .header_param(Parameter()
                          .key('accept')
                          .value('application/json'))
            .body_serializer(APIHelper.json_serialize)
            .auth(Single('global'))
        ).response(
            ResponseHandler()
            .deserializer(APIHelper.json_deserialize)
            .deserialize_into(UpdateLicenseResponse.from_dictionary)
        ).execute()

    def update_license(self,
                       site_id,
                       body):
        """Does a PUT request to /ranger/license/{site_id}.

        Update license

        Args:
            site_id (int): On which site to operate
            body (LicenseRequest): Set license

        Returns:
            UpdateLicenseResponse: 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.

        """

        return super().new_api_call_builder.request(
            RequestBuilder().server(Server.DEFAULT)
            .path('/ranger/license/{site_id}')
            .http_method(HttpMethodEnum.PUT)
            .template_param(Parameter()
                            .key('site_id')
                            .value(site_id)
                            .should_encode(True))
            .header_param(Parameter()
                          .key('Content-Type')
                          .value('application/json'))
            .body_param(Parameter()
                        .value(body))
            .header_param(Parameter()
                          .key('accept')
                          .value('application/json'))
            .body_serializer(APIHelper.json_serialize)
            .auth(Single('global'))
        ).response(
            ResponseHandler()
            .deserializer(APIHelper.json_deserialize)
            .deserialize_into(UpdateLicenseResponse.from_dictionary)
        ).execute()
