# coding: utf-8

"""
    Knetik Platform API Documentation latest 

    This is the spec for the Knetik API.  Use this in conjunction with the documentation found at https://knetikcloud.com.

    OpenAPI spec version: latest 
    Contact: support@knetik.com
    Generated by: https://github.com/swagger-api/swagger-codegen.git
"""


from __future__ import absolute_import

import sys
import os
import re

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

from ..api_client import ApiClient


class RuleEngineTriggersApi(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):
        if api_client is None:
            api_client = ApiClient()
        self.api_client = api_client

    def create_bre_trigger(self, **kwargs):
        """
        Create a trigger
        Customer added triggers will not be fired automatically or have rules associated with them by default. Custom rules must be added to get use from the trigger and it must then be fired from the outside. See the Bre Event services. <br><br><b>Permissions Needed:</b> BRE_RULE_ENGINE_TRIGGERS_ADMIN
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async=True
        >>> thread = api.create_bre_trigger(async=True)
        >>> result = thread.get()

        :param async bool
        :param BreTriggerResource bre_trigger_resource: The BRE trigger resource object
        :return: BreTriggerResource
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('async'):
            return self.create_bre_trigger_with_http_info(**kwargs)
        else:
            (data) = self.create_bre_trigger_with_http_info(**kwargs)
            return data

    def create_bre_trigger_with_http_info(self, **kwargs):
        """
        Create a trigger
        Customer added triggers will not be fired automatically or have rules associated with them by default. Custom rules must be added to get use from the trigger and it must then be fired from the outside. See the Bre Event services. <br><br><b>Permissions Needed:</b> BRE_RULE_ENGINE_TRIGGERS_ADMIN
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async=True
        >>> thread = api.create_bre_trigger_with_http_info(async=True)
        >>> result = thread.get()

        :param async bool
        :param BreTriggerResource bre_trigger_resource: The BRE trigger resource object
        :return: BreTriggerResource
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = ['bre_trigger_resource']
        all_params.append('async')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

        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_bre_trigger" % key
                )
            params[key] = val
        del params['kwargs']


        collection_formats = {}

        path_params = {}

        query_params = []

        header_params = {}

        form_params = []
        local_var_files = {}

        body_params = None
        if 'bre_trigger_resource' in params:
            body_params = params['bre_trigger_resource']
        # HTTP header `Accept`
        header_params['Accept'] = self.api_client.\
            select_header_accept(['application/json'])

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

        # Authentication setting
        auth_settings = ['oauth2_client_credentials_grant', 'oauth2_password_grant']

        return self.api_client.call_api('/bre/triggers', 'POST',
                                        path_params,
                                        query_params,
                                        header_params,
                                        body=body_params,
                                        post_params=form_params,
                                        files=local_var_files,
                                        response_type='BreTriggerResource',
                                        auth_settings=auth_settings,
                                        async=params.get('async'),
                                        _return_http_data_only=params.get('_return_http_data_only'),
                                        _preload_content=params.get('_preload_content', True),
                                        _request_timeout=params.get('_request_timeout'),
                                        collection_formats=collection_formats)

    def delete_bre_trigger(self, event_name, **kwargs):
        """
        Delete a trigger
        May fail if there are existing rules against it. Cannot delete core triggers. <br><br><b>Permissions Needed:</b> BRE_RULE_ENGINE_TRIGGERS_ADMIN
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async=True
        >>> thread = api.delete_bre_trigger(event_name, async=True)
        >>> result = thread.get()

        :param async bool
        :param str event_name: The trigger event name (required)
        :return: None
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('async'):
            return self.delete_bre_trigger_with_http_info(event_name, **kwargs)
        else:
            (data) = self.delete_bre_trigger_with_http_info(event_name, **kwargs)
            return data

    def delete_bre_trigger_with_http_info(self, event_name, **kwargs):
        """
        Delete a trigger
        May fail if there are existing rules against it. Cannot delete core triggers. <br><br><b>Permissions Needed:</b> BRE_RULE_ENGINE_TRIGGERS_ADMIN
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async=True
        >>> thread = api.delete_bre_trigger_with_http_info(event_name, async=True)
        >>> result = thread.get()

        :param async bool
        :param str event_name: The trigger event name (required)
        :return: None
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = ['event_name']
        all_params.append('async')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

        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 delete_bre_trigger" % key
                )
            params[key] = val
        del params['kwargs']
        # verify the required parameter 'event_name' is set
        if ('event_name' not in params) or (params['event_name'] is None):
            raise ValueError("Missing the required parameter `event_name` when calling `delete_bre_trigger`")


        collection_formats = {}

        path_params = {}
        if 'event_name' in params:
            path_params['event_name'] = params['event_name']

        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'])

        # Authentication setting
        auth_settings = ['oauth2_client_credentials_grant', 'oauth2_password_grant']

        return self.api_client.call_api('/bre/triggers/{event_name}', 'DELETE',
                                        path_params,
                                        query_params,
                                        header_params,
                                        body=body_params,
                                        post_params=form_params,
                                        files=local_var_files,
                                        response_type=None,
                                        auth_settings=auth_settings,
                                        async=params.get('async'),
                                        _return_http_data_only=params.get('_return_http_data_only'),
                                        _preload_content=params.get('_preload_content', True),
                                        _request_timeout=params.get('_request_timeout'),
                                        collection_formats=collection_formats)

    def get_bre_trigger(self, event_name, **kwargs):
        """
        Get a single trigger
        <b>Permissions Needed:</b> BRE_RULE_ENGINE_TRIGGERS_USER
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async=True
        >>> thread = api.get_bre_trigger(event_name, async=True)
        >>> result = thread.get()

        :param async bool
        :param str event_name: The trigger event name (required)
        :return: BreTriggerResource
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('async'):
            return self.get_bre_trigger_with_http_info(event_name, **kwargs)
        else:
            (data) = self.get_bre_trigger_with_http_info(event_name, **kwargs)
            return data

    def get_bre_trigger_with_http_info(self, event_name, **kwargs):
        """
        Get a single trigger
        <b>Permissions Needed:</b> BRE_RULE_ENGINE_TRIGGERS_USER
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async=True
        >>> thread = api.get_bre_trigger_with_http_info(event_name, async=True)
        >>> result = thread.get()

        :param async bool
        :param str event_name: The trigger event name (required)
        :return: BreTriggerResource
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = ['event_name']
        all_params.append('async')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

        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_bre_trigger" % key
                )
            params[key] = val
        del params['kwargs']
        # verify the required parameter 'event_name' is set
        if ('event_name' not in params) or (params['event_name'] is None):
            raise ValueError("Missing the required parameter `event_name` when calling `get_bre_trigger`")


        collection_formats = {}

        path_params = {}
        if 'event_name' in params:
            path_params['event_name'] = params['event_name']

        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'])

        # Authentication setting
        auth_settings = ['oauth2_client_credentials_grant', 'oauth2_password_grant']

        return self.api_client.call_api('/bre/triggers/{event_name}', 'GET',
                                        path_params,
                                        query_params,
                                        header_params,
                                        body=body_params,
                                        post_params=form_params,
                                        files=local_var_files,
                                        response_type='BreTriggerResource',
                                        auth_settings=auth_settings,
                                        async=params.get('async'),
                                        _return_http_data_only=params.get('_return_http_data_only'),
                                        _preload_content=params.get('_preload_content', True),
                                        _request_timeout=params.get('_request_timeout'),
                                        collection_formats=collection_formats)

    def get_bre_triggers(self, **kwargs):
        """
        List triggers
        <b>Permissions Needed:</b> BRE_RULE_ENGINE_TRIGGERS_USER
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async=True
        >>> thread = api.get_bre_triggers(async=True)
        >>> result = thread.get()

        :param async bool
        :param bool filter_system: Filter for triggers that are system triggers when true, or not when false. Leave off for both mixed
        :param str filter_category: Filter for triggers that are within a specific category
        :param str filter_tags: Filter for triggers that have all of the given tags (comma separated list)
        :param str filter_name: Filter for triggers that have names containing the given string
        :param str filter_search: Filter for triggers containing the given words somewhere within name, description and tags
        :param int size: The number of objects returned per page
        :param int page: The number of the page returned, starting with 1
        :return: PageResourceBreTriggerResource
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('async'):
            return self.get_bre_triggers_with_http_info(**kwargs)
        else:
            (data) = self.get_bre_triggers_with_http_info(**kwargs)
            return data

    def get_bre_triggers_with_http_info(self, **kwargs):
        """
        List triggers
        <b>Permissions Needed:</b> BRE_RULE_ENGINE_TRIGGERS_USER
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async=True
        >>> thread = api.get_bre_triggers_with_http_info(async=True)
        >>> result = thread.get()

        :param async bool
        :param bool filter_system: Filter for triggers that are system triggers when true, or not when false. Leave off for both mixed
        :param str filter_category: Filter for triggers that are within a specific category
        :param str filter_tags: Filter for triggers that have all of the given tags (comma separated list)
        :param str filter_name: Filter for triggers that have names containing the given string
        :param str filter_search: Filter for triggers containing the given words somewhere within name, description and tags
        :param int size: The number of objects returned per page
        :param int page: The number of the page returned, starting with 1
        :return: PageResourceBreTriggerResource
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = ['filter_system', 'filter_category', 'filter_tags', 'filter_name', 'filter_search', 'size', 'page']
        all_params.append('async')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

        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_bre_triggers" % key
                )
            params[key] = val
        del params['kwargs']


        collection_formats = {}

        path_params = {}

        query_params = []
        if 'filter_system' in params:
            query_params.append(('filter_system', params['filter_system']))
        if 'filter_category' in params:
            query_params.append(('filter_category', params['filter_category']))
        if 'filter_tags' in params:
            query_params.append(('filter_tags', params['filter_tags']))
        if 'filter_name' in params:
            query_params.append(('filter_name', params['filter_name']))
        if 'filter_search' in params:
            query_params.append(('filter_search', params['filter_search']))
        if 'size' in params:
            query_params.append(('size', params['size']))
        if 'page' in params:
            query_params.append(('page', params['page']))

        header_params = {}

        form_params = []
        local_var_files = {}

        body_params = None
        # HTTP header `Accept`
        header_params['Accept'] = self.api_client.\
            select_header_accept(['application/json'])

        # Authentication setting
        auth_settings = ['oauth2_client_credentials_grant', 'oauth2_password_grant']

        return self.api_client.call_api('/bre/triggers', 'GET',
                                        path_params,
                                        query_params,
                                        header_params,
                                        body=body_params,
                                        post_params=form_params,
                                        files=local_var_files,
                                        response_type='PageResourceBreTriggerResource',
                                        auth_settings=auth_settings,
                                        async=params.get('async'),
                                        _return_http_data_only=params.get('_return_http_data_only'),
                                        _preload_content=params.get('_preload_content', True),
                                        _request_timeout=params.get('_request_timeout'),
                                        collection_formats=collection_formats)

    def update_bre_trigger(self, event_name, **kwargs):
        """
        Update a trigger
        May fail if new parameters mismatch requirements of existing rules. Cannot update core triggers. <br><br><b>Permissions Needed:</b> BRE_RULE_ENGINE_TRIGGERS_ADMIN
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async=True
        >>> thread = api.update_bre_trigger(event_name, async=True)
        >>> result = thread.get()

        :param async bool
        :param str event_name: The trigger event name (required)
        :param BreTriggerResource bre_trigger_resource: The BRE trigger resource object
        :return: BreTriggerResource
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('async'):
            return self.update_bre_trigger_with_http_info(event_name, **kwargs)
        else:
            (data) = self.update_bre_trigger_with_http_info(event_name, **kwargs)
            return data

    def update_bre_trigger_with_http_info(self, event_name, **kwargs):
        """
        Update a trigger
        May fail if new parameters mismatch requirements of existing rules. Cannot update core triggers. <br><br><b>Permissions Needed:</b> BRE_RULE_ENGINE_TRIGGERS_ADMIN
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async=True
        >>> thread = api.update_bre_trigger_with_http_info(event_name, async=True)
        >>> result = thread.get()

        :param async bool
        :param str event_name: The trigger event name (required)
        :param BreTriggerResource bre_trigger_resource: The BRE trigger resource object
        :return: BreTriggerResource
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = ['event_name', 'bre_trigger_resource']
        all_params.append('async')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

        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 update_bre_trigger" % key
                )
            params[key] = val
        del params['kwargs']
        # verify the required parameter 'event_name' is set
        if ('event_name' not in params) or (params['event_name'] is None):
            raise ValueError("Missing the required parameter `event_name` when calling `update_bre_trigger`")


        collection_formats = {}

        path_params = {}
        if 'event_name' in params:
            path_params['event_name'] = params['event_name']

        query_params = []

        header_params = {}

        form_params = []
        local_var_files = {}

        body_params = None
        if 'bre_trigger_resource' in params:
            body_params = params['bre_trigger_resource']
        # HTTP header `Accept`
        header_params['Accept'] = self.api_client.\
            select_header_accept(['application/json'])

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

        # Authentication setting
        auth_settings = ['oauth2_client_credentials_grant', 'oauth2_password_grant']

        return self.api_client.call_api('/bre/triggers/{event_name}', 'PUT',
                                        path_params,
                                        query_params,
                                        header_params,
                                        body=body_params,
                                        post_params=form_params,
                                        files=local_var_files,
                                        response_type='BreTriggerResource',
                                        auth_settings=auth_settings,
                                        async=params.get('async'),
                                        _return_http_data_only=params.get('_return_http_data_only'),
                                        _preload_content=params.get('_preload_content', True),
                                        _request_timeout=params.get('_request_timeout'),
                                        collection_formats=collection_formats)
