# -*- 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


class QueriesController(BaseController):

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

    def get_queries(self,
                    sort=None,
                    page=None,
                    per_page=None,
                    name__icontains=None,
                    site_id__exact=None):
        """Does a GET request to /ranger/queries.

        Get all queries and their information

        Args:
            sort (Sort1Enum, optional): TODO: type description here.
            page (int, optional): TODO: type description here.
            per_page (int, optional): TODO: type description here.
            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/queries')
            .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_query(self,
                           body):
        """Does a POST request to /ranger/queries.

        This route creates a query

        Args:
            body (CreateANewQuery): 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/queries')
            .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_query(self,
                       content_type):
        """Does a DELETE request to /ranger/queries.

        Delete a query 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/queries')
            .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_query(self,
                              resource_id,
                              body):
        """Does a POST request to /ranger/queries/{resource_id}.

        This route updates a query

        Args:
            resource_id (string): Resource ID of the query to update
            body (CreateANewQuery): 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/queries/{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 get_information_for_all_queries(self):
        """Does a GET request to /ranger/queries/get_types.

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

        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.

        """

        return super().new_api_call_builder.request(
            RequestBuilder().server(Server.DEFAULT)
            .path('/ranger/queries/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_queries_fields_types_and_validations(self):
        """Does a GET request to /ranger/queries/get_params.

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

        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.

        """

        return super().new_api_call_builder.request(
            RequestBuilder().server(Server.DEFAULT)
            .path('/ranger/queries/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()
