# coding: utf-8

"""
SyncTargetApi.py
Copyright 2016 SmartBear Software

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
"""

from __future__ import absolute_import

import sys
import os
import re

# python 2 and python 3 compatibility library
from six import iteritems

from ..configuration import Configuration
from ..api_client import ApiClient


class SyncTargetApi(object):
    """
    NOTE: This class is auto generated by the swagger code generator program.
    Do not edit the class manually.
    Ref: https://github.com/swagger-api/swagger-codegen
    """

    def __init__(self, api_client=None):
        config = Configuration()
        if api_client:
            self.api_client = api_client
        else:
            if not config.api_client:
                config.api_client = ApiClient()
            self.api_client = config.api_client

    def create_policies_policy_cancel_item(self, policies_policy_cancel_item, policy, **kwargs):
        """
        
        Cancel the most recent SyncIQ job for this policy from the target side.

        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please define a `callback` function
        to be invoked when receiving the response.
        >>> def callback_function(response):
        >>>     pprint(response)
        >>>
        >>> thread = api.create_policies_policy_cancel_item(policies_policy_cancel_item, policy, callback=callback_function)

        :param callback function: The callback function
            for asynchronous request. (optional)
        :param Empty policies_policy_cancel_item:  (required)
        :param str policy:  (required)
        :return: CreateResponse
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = ['policies_policy_cancel_item', 'policy']
        all_params.append('callback')

        params = locals()
        for key, val in iteritems(params['kwargs']):
            if key not in all_params:
                raise TypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method create_policies_policy_cancel_item" % key
                )
            params[key] = val
        del params['kwargs']

        # verify the required parameter 'policies_policy_cancel_item' is set
        if ('policies_policy_cancel_item' not in params) or (params['policies_policy_cancel_item'] is None):
            raise ValueError("Missing the required parameter `policies_policy_cancel_item` when calling `create_policies_policy_cancel_item`")
        # verify the required parameter 'policy' is set
        if ('policy' not in params) or (params['policy'] is None):
            raise ValueError("Missing the required parameter `policy` when calling `create_policies_policy_cancel_item`")


        resource_path = '/platform/1/sync/target/policies/{Policy}/cancel'.replace('{format}', 'json')
        path_params = {}
        if 'policy' in params:
            path_params['Policy'] = params['policy']

        query_params = {}

        header_params = {}

        form_params = []
        local_var_files = {}

        body_params = None
        if 'policies_policy_cancel_item' in params:
            body_params = params['policies_policy_cancel_item']

        # HTTP header `Accept`
        header_params['Accept'] = self.api_client.\
            select_header_accept(['application/json'])
        if not header_params['Accept']:
            del header_params['Accept']

        # HTTP header `Content-Type`
        header_params['Content-Type'] = self.api_client.\
            select_header_content_type(['application/json'])

        # Authentication setting
        auth_settings = ['basic_auth']

        response = self.api_client.call_api(resource_path, 'POST',
                                            path_params,
                                            query_params,
                                            header_params,
                                            body=body_params,
                                            post_params=form_params,
                                            files=local_var_files,
                                            response_type='CreateResponse',
                                            auth_settings=auth_settings,
                                            callback=params.get('callback'))
        return response

    def get_reports_report_subreport(self, reports_report_subreport_id, rid, **kwargs):
        """
        
        View a single SyncIQ target subreport.

        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please define a `callback` function
        to be invoked when receiving the response.
        >>> def callback_function(response):
        >>>     pprint(response)
        >>>
        >>> thread = api.get_reports_report_subreport(reports_report_subreport_id, rid, callback=callback_function)

        :param callback function: The callback function
            for asynchronous request. (optional)
        :param str reports_report_subreport_id: View a single SyncIQ target subreport. (required)
        :param str rid:  (required)
        :return: ReportsReportSubreports
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = ['reports_report_subreport_id', 'rid']
        all_params.append('callback')

        params = locals()
        for key, val in iteritems(params['kwargs']):
            if key not in all_params:
                raise TypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method get_reports_report_subreport" % key
                )
            params[key] = val
        del params['kwargs']

        # verify the required parameter 'reports_report_subreport_id' is set
        if ('reports_report_subreport_id' not in params) or (params['reports_report_subreport_id'] is None):
            raise ValueError("Missing the required parameter `reports_report_subreport_id` when calling `get_reports_report_subreport`")
        # verify the required parameter 'rid' is set
        if ('rid' not in params) or (params['rid'] is None):
            raise ValueError("Missing the required parameter `rid` when calling `get_reports_report_subreport`")


        resource_path = '/platform/1/sync/target/reports/{Rid}/subreports/{ReportsReportSubreportId}'.replace('{format}', 'json')
        path_params = {}
        if 'reports_report_subreport_id' in params:
            path_params['ReportsReportSubreportId'] = params['reports_report_subreport_id']
        if 'rid' in params:
            path_params['Rid'] = params['rid']

        query_params = {}

        header_params = {}

        form_params = []
        local_var_files = {}

        body_params = None

        # HTTP header `Accept`
        header_params['Accept'] = self.api_client.\
            select_header_accept(['application/json'])
        if not header_params['Accept']:
            del header_params['Accept']

        # HTTP header `Content-Type`
        header_params['Content-Type'] = self.api_client.\
            select_header_content_type(['application/json'])

        # Authentication setting
        auth_settings = ['basic_auth']

        response = self.api_client.call_api(resource_path, 'GET',
                                            path_params,
                                            query_params,
                                            header_params,
                                            body=body_params,
                                            post_params=form_params,
                                            files=local_var_files,
                                            response_type='ReportsReportSubreports',
                                            auth_settings=auth_settings,
                                            callback=params.get('callback'))
        return response

    def get_reports_report_subreports(self, rid, **kwargs):
        """
        
        Get a list of SyncIQ target subreports for a report.

        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please define a `callback` function
        to be invoked when receiving the response.
        >>> def callback_function(response):
        >>>     pprint(response)
        >>>
        >>> thread = api.get_reports_report_subreports(rid, callback=callback_function)

        :param callback function: The callback function
            for asynchronous request. (optional)
        :param str rid:  (required)
        :param str sort: The field that will be used for sorting.
        :param str resume: Continue returning results from previous call using this token (token should come from the previous call, resume cannot be used with other options).
        :param int newer_than: Filter the returned reports to include only those whose jobs started more recently than the specified number of days ago.
        :param str state: Filter the returned reports to include only those whose jobs are in this state.
        :param int limit: Return no more than this many results at once (see resume).
        :param str dir: The direction of the sort.
        :return: ReportsReportSubreportsExtended
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = ['rid', 'sort', 'resume', 'newer_than', 'state', 'limit', 'dir']
        all_params.append('callback')

        params = locals()
        for key, val in iteritems(params['kwargs']):
            if key not in all_params:
                raise TypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method get_reports_report_subreports" % key
                )
            params[key] = val
        del params['kwargs']

        # verify the required parameter 'rid' is set
        if ('rid' not in params) or (params['rid'] is None):
            raise ValueError("Missing the required parameter `rid` when calling `get_reports_report_subreports`")

        if 'limit' in params and params['limit'] < 1.0: 
            raise ValueError("Invalid value for parameter `limit` when calling `get_reports_report_subreports`, must be a value greater than or equal to `1.0`")

        resource_path = '/platform/1/sync/target/reports/{Rid}/subreports'.replace('{format}', 'json')
        path_params = {}
        if 'rid' in params:
            path_params['Rid'] = params['rid']

        query_params = {}
        if 'sort' in params:
            query_params['sort'] = params['sort']
        if 'resume' in params:
            query_params['resume'] = params['resume']
        if 'newer_than' in params:
            query_params['newer_than'] = params['newer_than']
        if 'state' in params:
            query_params['state'] = params['state']
        if 'limit' in params:
            query_params['limit'] = params['limit']
        if 'dir' in params:
            query_params['dir'] = params['dir']

        header_params = {}

        form_params = []
        local_var_files = {}

        body_params = None

        # HTTP header `Accept`
        header_params['Accept'] = self.api_client.\
            select_header_accept(['application/json'])
        if not header_params['Accept']:
            del header_params['Accept']

        # HTTP header `Content-Type`
        header_params['Content-Type'] = self.api_client.\
            select_header_content_type(['application/json'])

        # Authentication setting
        auth_settings = ['basic_auth']

        response = self.api_client.call_api(resource_path, 'GET',
                                            path_params,
                                            query_params,
                                            header_params,
                                            body=body_params,
                                            post_params=form_params,
                                            files=local_var_files,
                                            response_type='ReportsReportSubreportsExtended',
                                            auth_settings=auth_settings,
                                            callback=params.get('callback'))
        return response
