# coding: utf-8

"""
    UUDEXApi

    uudex api  # noqa: E501

    OpenAPI spec version: 1.0
    Contact: jeff.welsh@pnnl.gov
    Generated by: https://github.com/swagger-api/swagger-codegen.git
"""

from __future__ import absolute_import

import re  # noqa: F401

# python 2 and python 3 compatibility library
import six

from uudex_client.api_client import ApiClient


class SubjectApi(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_subject(self, **kwargs):  # noqa: E501
        """Creates a Subject if the calling participant is authorized  # noqa: E501

        The invoker must have either the ParticipantAdmin role or the SubjectAdmin role.  The ability of a non-admin invoker to create a Subject is also determined by any defined Subject Policy rules.  See the UUDEX documentation for further discussion.  A UUDEX Admin may create a Subject without restrictions.  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.create_subject(async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param Subject body:
        :return: Subject
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('async_req'):
            return self.create_subject_with_http_info(**kwargs)  # noqa: E501
        else:
            (data) = self.create_subject_with_http_info(**kwargs)  # noqa: E501
            return data

    def create_subject_with_http_info(self, **kwargs):  # noqa: E501
        """Creates a Subject if the calling participant is authorized  # noqa: E501

        The invoker must have either the ParticipantAdmin role or the SubjectAdmin role.  The ability of a non-admin invoker to create a Subject is also determined by any defined Subject Policy rules.  See the UUDEX documentation for further discussion.  A UUDEX Admin may create a Subject without restrictions.  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.create_subject_with_http_info(async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param Subject body:
        :return: Subject
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = ['body']  # noqa: E501
        all_params.append('async_req')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

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

        collection_formats = {}

        path_params = {}

        query_params = []

        header_params = {}

        form_params = []
        local_var_files = {}

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

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

        # Authentication setting
        auth_settings = []  # noqa: E501

        return self.api_client.call_api(
            '/subjects', 'POST',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='Subject',  # noqa: E501
            auth_settings=auth_settings,
            async_req=params.get('async_req'),
            _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_subject(self, subject_uuid, **kwargs):  # noqa: E501
        """Delete a single Subject the invoker is authorized to use  # noqa: E501

        The invoker must have either the ParticipantAdmin role or the SubjectAdmin role AND the Subject must be owned by the invoker's Participant.  A UUDEX Admin may delete any Subject without restrictions.  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.delete_subject(subject_uuid, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str subject_uuid: (required)
        :return: None
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('async_req'):
            return self.delete_subject_with_http_info(subject_uuid, **kwargs)  # noqa: E501
        else:
            (data) = self.delete_subject_with_http_info(subject_uuid, **kwargs)  # noqa: E501
            return data

    def delete_subject_with_http_info(self, subject_uuid, **kwargs):  # noqa: E501
        """Delete a single Subject the invoker is authorized to use  # noqa: E501

        The invoker must have either the ParticipantAdmin role or the SubjectAdmin role AND the Subject must be owned by the invoker's Participant.  A UUDEX Admin may delete any Subject without restrictions.  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.delete_subject_with_http_info(subject_uuid, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str subject_uuid: (required)
        :return: None
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = ['subject_uuid']  # noqa: E501
        all_params.append('async_req')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

        params = locals()
        for key, val in six.iteritems(params['kwargs']):
            if key not in all_params:
                raise TypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method delete_subject" % key
                )
            params[key] = val
        del params['kwargs']
        # verify the required parameter 'subject_uuid' is set
        if ('subject_uuid' not in params or
                params['subject_uuid'] is None):
            raise ValueError("Missing the required parameter `subject_uuid` when calling `delete_subject`")  # noqa: E501

        collection_formats = {}

        path_params = {}
        if 'subject_uuid' in params:
            path_params['subject_uuid'] = params['subject_uuid']  # noqa: E501

        query_params = []

        header_params = {}

        form_params = []
        local_var_files = {}

        body_params = None
        # Authentication setting
        auth_settings = []  # noqa: E501

        return self.api_client.call_api(
            '/subjects/{subject_uuid}', 'DELETE',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type=None,  # noqa: E501
            auth_settings=auth_settings,
            async_req=params.get('async_req'),
            _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 discover_subjects(self, **kwargs):  # noqa: E501
        """Returns a collection of Subjects the calling endpoint is authorized to view.  Optionally filter by subject name.  # noqa: E501

        Returns a collection of Subjects the calling endpoint is authorized to view.  Authorized to view is defined as the invoker having been granted the DISCOVER privilege to the Subjects.   # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.discover_subjects(async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :return: list[SubjectDiscovered]
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('async_req'):
            return self.discover_subjects_with_http_info(**kwargs)  # noqa: E501
        else:
            (data) = self.discover_subjects_with_http_info(**kwargs)  # noqa: E501
            return data

    def discover_subjects_with_http_info(self, **kwargs):  # noqa: E501
        """Returns a collection of Subjects the calling endpoint is authorized to view.  Optionally filter by subject name.  # noqa: E501

        Returns a collection of Subjects the calling endpoint is authorized to view.  Authorized to view is defined as the invoker having been granted the DISCOVER privilege to the Subjects.   # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.discover_subjects_with_http_info(async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :return: list[SubjectDiscovered]
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = []  # noqa: E501
        all_params.append('async_req')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

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

        collection_formats = {}

        path_params = {}

        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'])  # noqa: E501

        # Authentication setting
        auth_settings = []  # noqa: E501

        return self.api_client.call_api(
            '/subjects/discover', 'GET',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='list[SubjectDiscovered]',  # noqa: E501
            auth_settings=auth_settings,
            async_req=params.get('async_req'),
            _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_subject(self, subject_uuid, **kwargs):  # noqa: E501
        """Get a single Subject the invoker is authorized to use  # noqa: E501

        The Subject must be owned by the invoker's Participant.  Invoker must have the SubjectAdmin role or the ParticipantAdmin role.  A UUDEX Admin may get any Subject in the system.  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.get_subject(subject_uuid, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str subject_uuid: (required)
        :return: SubjectEnriched
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('async_req'):
            return self.get_subject_with_http_info(subject_uuid, **kwargs)  # noqa: E501
        else:
            (data) = self.get_subject_with_http_info(subject_uuid, **kwargs)  # noqa: E501
            return data

    def get_subject_with_http_info(self, subject_uuid, **kwargs):  # noqa: E501
        """Get a single Subject the invoker is authorized to use  # noqa: E501

        The Subject must be owned by the invoker's Participant.  Invoker must have the SubjectAdmin role or the ParticipantAdmin role.  A UUDEX Admin may get any Subject in the system.  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.get_subject_with_http_info(subject_uuid, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str subject_uuid: (required)
        :return: SubjectEnriched
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = ['subject_uuid']  # noqa: E501
        all_params.append('async_req')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

        params = locals()
        for key, val in six.iteritems(params['kwargs']):
            if key not in all_params:
                raise TypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method get_subject" % key
                )
            params[key] = val
        del params['kwargs']
        # verify the required parameter 'subject_uuid' is set
        if ('subject_uuid' not in params or
                params['subject_uuid'] is None):
            raise ValueError("Missing the required parameter `subject_uuid` when calling `get_subject`")  # noqa: E501

        collection_formats = {}

        path_params = {}
        if 'subject_uuid' in params:
            path_params['subject_uuid'] = params['subject_uuid']  # noqa: E501

        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'])  # noqa: E501

        # Authentication setting
        auth_settings = []  # noqa: E501

        return self.api_client.call_api(
            '/subjects/{subject_uuid}', 'GET',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='SubjectEnriched',  # noqa: E501
            auth_settings=auth_settings,
            async_req=params.get('async_req'),
            _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_subjects(self, **kwargs):  # noqa: E501
        """Return a collection of Subjects  # noqa: E501

        Gets all Subjects owned by the invoker's Participant.  Invoker must have the SubjectAdmin role or the ParticipantAdmin role.  A UUDEX Admin may get all Subjects in the system.  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.get_subjects(async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :return: list[SubjectEnriched]
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('async_req'):
            return self.get_subjects_with_http_info(**kwargs)  # noqa: E501
        else:
            (data) = self.get_subjects_with_http_info(**kwargs)  # noqa: E501
            return data

    def get_subjects_with_http_info(self, **kwargs):  # noqa: E501
        """Return a collection of Subjects  # noqa: E501

        Gets all Subjects owned by the invoker's Participant.  Invoker must have the SubjectAdmin role or the ParticipantAdmin role.  A UUDEX Admin may get all Subjects in the system.  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.get_subjects_with_http_info(async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :return: list[SubjectEnriched]
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = []  # noqa: E501
        all_params.append('async_req')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

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

        collection_formats = {}

        path_params = {}

        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'])  # noqa: E501

        # Authentication setting
        auth_settings = []  # noqa: E501

        return self.api_client.call_api(
            '/subjects', 'GET',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='list[SubjectEnriched]',  # noqa: E501
            auth_settings=auth_settings,
            async_req=params.get('async_req'),
            _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 publish_message(self, subject_uuid, **kwargs):  # noqa: E501
        """Publishes one or more messages  # noqa: E501

        Invoker must have the SUBSCRIBE privilege on the the Subject or own the Subject.   # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.publish_message(subject_uuid, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str subject_uuid: (required)
        :param list[MessagePublish] body:
        :return: MessagePublishResp
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('async_req'):
            return self.publish_message_with_http_info(subject_uuid, **kwargs)  # noqa: E501
        else:
            (data) = self.publish_message_with_http_info(subject_uuid, **kwargs)  # noqa: E501
            return data

    def publish_message_with_http_info(self, subject_uuid, **kwargs):  # noqa: E501
        """Publishes one or more messages  # noqa: E501

        Invoker must have the SUBSCRIBE privilege on the the Subject or own the Subject.   # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.publish_message_with_http_info(subject_uuid, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str subject_uuid: (required)
        :param list[MessagePublish] body:
        :return: MessagePublishResp
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = ['subject_uuid', 'body']  # noqa: E501
        all_params.append('async_req')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

        params = locals()
        for key, val in six.iteritems(params['kwargs']):
            if key not in all_params:
                raise TypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method publish_message" % key
                )
            params[key] = val
        del params['kwargs']
        # verify the required parameter 'subject_uuid' is set
        if ('subject_uuid' not in params or
                params['subject_uuid'] is None):
            raise ValueError("Missing the required parameter `subject_uuid` when calling `publish_message`")  # noqa: E501

        collection_formats = {}

        path_params = {}
        if 'subject_uuid' in params:
            path_params['subject_uuid'] = params['subject_uuid']  # noqa: E501

        query_params = []

        header_params = {}

        form_params = []
        local_var_files = {}

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

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

        # Authentication setting
        auth_settings = []  # noqa: E501

        return self.api_client.call_api(
            '/subjects/{subject_uuid}/publish', 'POST',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='MessagePublishResp',  # noqa: E501
            auth_settings=auth_settings,
            async_req=params.get('async_req'),
            _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_subject(self, subject_uuid, **kwargs):  # noqa: E501
        """Update a single Subject the invoker is authorized to use  # noqa: E501

        The invoker must have either the ParticipantAdmin role or the SubjectAdmin role AND the Subject must be owned by the invoker's Participant.  A UUDEX Admin may update any Subject without restrictions.  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.update_subject(subject_uuid, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str subject_uuid: (required)
        :param Subject body:
        :return: Subject
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('async_req'):
            return self.update_subject_with_http_info(subject_uuid, **kwargs)  # noqa: E501
        else:
            (data) = self.update_subject_with_http_info(subject_uuid, **kwargs)  # noqa: E501
            return data

    def update_subject_with_http_info(self, subject_uuid, **kwargs):  # noqa: E501
        """Update a single Subject the invoker is authorized to use  # noqa: E501

        The invoker must have either the ParticipantAdmin role or the SubjectAdmin role AND the Subject must be owned by the invoker's Participant.  A UUDEX Admin may update any Subject without restrictions.  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.update_subject_with_http_info(subject_uuid, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str subject_uuid: (required)
        :param Subject body:
        :return: Subject
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = ['subject_uuid', 'body']  # noqa: E501
        all_params.append('async_req')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

        params = locals()
        for key, val in six.iteritems(params['kwargs']):
            if key not in all_params:
                raise TypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method update_subject" % key
                )
            params[key] = val
        del params['kwargs']
        # verify the required parameter 'subject_uuid' is set
        if ('subject_uuid' not in params or
                params['subject_uuid'] is None):
            raise ValueError("Missing the required parameter `subject_uuid` when calling `update_subject`")  # noqa: E501

        collection_formats = {}

        path_params = {}
        if 'subject_uuid' in params:
            path_params['subject_uuid'] = params['subject_uuid']  # noqa: E501

        query_params = []

        header_params = {}

        form_params = []
        local_var_files = {}

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

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

        # Authentication setting
        auth_settings = []  # noqa: E501

        return self.api_client.call_api(
            '/subjects/{subject_uuid}', 'PATCH',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='Subject',  # noqa: E501
            auth_settings=auth_settings,
            async_req=params.get('async_req'),
            _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)
