# -*- 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_queries_response import GetQueriesResponse
from ctddocumentation.models.create_a_new_query_response import CreateANewQueryResponse
from ctddocumentation.models.delete_a_query_response import DeleteAQueryResponse
from ctddocumentation.models.object import Object
from ctddocumentation.models.get_active_detection_history_response import GetActiveDetectionHistoryResponse


class TasksController(BaseController):

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

    def get_tasks(self,
                  sort=None,
                  page=1,
                  per_page=20,
                  name__icontains=None,
                  site_id__exact=None):
        """Does a GET request to /ranger/scans.

        Get all tasks and their information

        Args:
            sort (Sort1Enum, optional): TODO: type description here.
            page (int, optional): TODO: type description here. Example: 1
            per_page (int, optional): TODO: type description here. Example:
                20
            name__icontains (string, optional): TODO: type description here.
            site_id__exact (int, optional): TODO: type description here.

        Returns:
            GetQueriesResponse: 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/scans')
            .http_method(HttpMethodEnum.GET)
            .query_param(Parameter()
                         .key('sort')
                         .value(sort))
            .query_param(Parameter()
                         .key('page')
                         .value(page))
            .query_param(Parameter()
                         .key('per_page')
                         .value(per_page))
            .query_param(Parameter()
                         .key('name__icontains')
                         .value(name__icontains))
            .query_param(Parameter()
                         .key('site_id__exact')
                         .value(site_id__exact))
            .header_param(Parameter()
                          .key('accept')
                          .value('application/json'))
            .auth(Single('global'))
        ).response(
            ResponseHandler()
            .deserializer(APIHelper.json_deserialize)
            .deserialize_into(GetQueriesResponse.from_dictionary)
        ).execute()

    def create_a_new_task(self,
                          body):
        """Does a POST request to /ranger/scans.

        This route creates a task

        Args:
            body (Createanewtask): TODO: type description here.

        Returns:
            CreateANewQueryResponse: 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/scans')
            .http_method(HttpMethodEnum.POST)
            .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(CreateANewQueryResponse.from_dictionary)
        ).execute()

    def delete_a_task(self,
                      content_type):
        """Does a DELETE request to /ranger/scans.

        Delete a task by a list of selected resource IDs

        Args:
            content_type (ContentTypeEnum): TODO: type description here.

        Returns:
            DeleteAQueryResponse: 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/scans')
            .http_method(HttpMethodEnum.DELETE)
            .header_param(Parameter()
                          .key('Content-Type')
                          .value(content_type))
            .header_param(Parameter()
                          .key('accept')
                          .value('application/json'))
            .auth(Single('global'))
        ).response(
            ResponseHandler()
            .deserializer(APIHelper.json_deserialize)
            .deserialize_into(DeleteAQueryResponse.from_dictionary)
        ).execute()

    def update_a_single_task(self,
                             resource_id,
                             body):
        """Does a POST request to /ranger/scans/{resource_id}.

        This route updates a task

        Args:
            resource_id (string): Resource ID of the task to update
            body (Createanewtask): TODO: type description here.

        Returns:
            CreateANewQueryResponse: 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/scans/{resource_id}')
            .http_method(HttpMethodEnum.POST)
            .template_param(Parameter()
                            .key('resource_id')
                            .value(resource_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(CreateANewQueryResponse.from_dictionary)
        ).execute()

    def information_of_all_tasks(self):
        """Does a GET request to /ranger/scans/get_types.

        Get descriptions and enums for all tasks (can be used later to
        retrieve parameters per task type enum)

        Returns:
            dict: 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/scans/get_types')
            .http_method(HttpMethodEnum.GET)
            .header_param(Parameter()
                          .key('accept')
                          .value('application/json'))
            .auth(Single('global'))
        ).response(
            ResponseHandler()
            .deserializer(APIHelper.json_deserialize)
            .deserialize_into(Object.from_dictionary)
        ).execute()

    def all_tasks_fields(self):
        """Does a GET request to /ranger/scans/get_params.

        This is used to determine the payload needed to be sent for
        creating/updating a task by a certain task type enum value

        Returns:
            dict: 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/scans/get_params')
            .http_method(HttpMethodEnum.GET)
            .header_param(Parameter()
                          .key('accept')
                          .value('application/json'))
            .auth(Single('global'))
        ).response(
            ResponseHandler()
            .deserializer(APIHelper.json_deserialize)
            .deserialize_into(Object.from_dictionary)
        ).execute()

    def get_active_detection_history(self,
                                     site_id__exact,
                                     sort=None):
        """Does a GET request to /ranger/active_history.

        Get active detection history

        Args:
            site_id__exact (int): TODO: type description here.
            sort (string, optional): TODO: type description here.

        Returns:
            GetActiveDetectionHistoryResponse: 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/active_history')
            .http_method(HttpMethodEnum.GET)
            .query_param(Parameter()
                         .key('site_id__exact')
                         .value(site_id__exact))
            .query_param(Parameter()
                         .key('sort')
                         .value(sort))
            .header_param(Parameter()
                          .key('accept')
                          .value('application/json'))
            .auth(Single('global'))
        ).response(
            ResponseHandler()
            .deserializer(APIHelper.json_deserialize)
            .deserialize_into(GetActiveDetectionHistoryResponse.from_dictionary)
        ).execute()
