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

"""
    ontraportlib.controllers.tasks_controller

    This file was automatically generated by APIMATIC BETA v2.0 on 11/14/2017
"""

from .base_controller import BaseController
from ..api_helper import APIHelper
from ..configuration import Configuration
from ..models.response import Response

class TasksController(BaseController):

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

    def create_task_cancel(self,
                           criteria):
        """Does a POST request to /task/cancel.

        To affect a single Task or list of specific Tasks, use the
        <strong>ids</strong> array in the <strong>criteria</strong> parameter.
        Otherwise, you should use <strong>performAll</strong> and other
        criteria to select a Group of Tasks to cancel.

        Args:
            criteria (Criteria): Criteria of the Tasks to cancel.

        Returns:
            Response: Response from the API. Successfully canceled tasks

        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
        _query_builder = Configuration.base_uri
        _query_builder += '/task/cancel'
        _query_url = APIHelper.clean_url(_query_builder)

        # Prepare headers
        _headers = {
            'accept': 'application/json',
            'content-type': 'application/json; charset=utf-8'
        }

        # Prepare and execute request
        _request = self.http_client.post(_query_url, headers=_headers, parameters=APIHelper.json_serialize(criteria))
        _context = self.execute_request(_request)        
        self.validate_response(_context)    

        # Return appropriate type
        return APIHelper.json_deserialize(_context.response.raw_body, Response.from_dictionary)

    def create_task_complete(self,
                             body):
        """Does a POST request to /task/complete.

        This will mark one or many Tasks as complete. As an option, you can
        assign a new Task for further follow-up. To affect a single Task or
        list of specific Tasks, use the <strong>ids</strong> array in the
        <strong>criteria</strong> parameter. Otherwise, you should use
        <strong>performAll</strong> and other criteria to select a Group of
        Tasks to complete.

        Args:
            body (TaskCompleteParams): Criteria and data of the Tasks to
                complete.

        Returns:
            Response: Response from the API. Successfully canceled tasks

        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
        _query_builder = Configuration.base_uri
        _query_builder += '/task/complete'
        _query_url = APIHelper.clean_url(_query_builder)

        # Prepare headers
        _headers = {
            'accept': 'application/json',
            'content-type': 'application/json; charset=utf-8'
        }

        # Prepare and execute request
        _request = self.http_client.post(_query_url, headers=_headers, parameters=APIHelper.json_serialize(body))
        _context = self.execute_request(_request)        
        self.validate_response(_context)    

        # Return appropriate type
        return APIHelper.json_deserialize(_context.response.raw_body, Response.from_dictionary)
