# coding: utf-8

"""
    Trackside Software TeamDB API v2.0

    This API enables you to access TeamDB data  # noqa: E501

    OpenAPI spec version: 2.0
    Contact: support@trackside.fr
    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 teamdbapi.api_client import ApiClient


class NotesAuthorizationApi(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 notes_authorization_get_notes_authorizations(self, itembase_id, **kwargs):  # noqa: E501
        """Get the list of authorizations for a given Id corresponding to an Event or a Car  # noqa: E501

        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.notes_authorization_get_notes_authorizations(itembase_id, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str itembase_id: Unique Id corresponding to an Event or a Car (required)
        :return: list[NotesAuthorization]
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('async_req'):
            return self.notes_authorization_get_notes_authorizations_with_http_info(itembase_id, **kwargs)  # noqa: E501
        else:
            (data) = self.notes_authorization_get_notes_authorizations_with_http_info(itembase_id, **kwargs)  # noqa: E501
            return data

    def notes_authorization_get_notes_authorizations_with_http_info(self, itembase_id, **kwargs):  # noqa: E501
        """Get the list of authorizations for a given Id corresponding to an Event or a Car  # noqa: E501

        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.notes_authorization_get_notes_authorizations_with_http_info(itembase_id, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str itembase_id: Unique Id corresponding to an Event or a Car (required)
        :return: list[NotesAuthorization]
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = ['itembase_id']  # 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 notes_authorization_get_notes_authorizations" % key
                )
            params[key] = val
        del params['kwargs']
        # verify the required parameter 'itembase_id' is set
        if self.api_client.client_side_validation and ('itembase_id' not in params or
                                                       params['itembase_id'] is None):  # noqa: E501
            raise ValueError("Missing the required parameter `itembase_id` when calling `notes_authorization_get_notes_authorizations`")  # noqa: E501

        collection_formats = {}

        path_params = {}
        if 'itembase_id' in params:
            path_params['itembaseId'] = params['itembase_id']  # 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', 'text/json'])  # noqa: E501

        # Authentication setting
        auth_settings = []  # noqa: E501

        return self.api_client.call_api(
            '/teamdbapi/v2.0/itembase/{itembaseId}/notesauthorizations', 'GET',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='list[NotesAuthorization]',  # 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 notes_authorization_has_acces(self, itembase_id, user_or_group_id, **kwargs):  # noqa: E501
        """Returns true if the user or group has access to the event or car  # noqa: E501

        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.notes_authorization_has_acces(itembase_id, user_or_group_id, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str itembase_id: Unique Id corresponding to an Event or a Car (required)
        :param str user_or_group_id: Unique Id corresponding to a User or a Group (required)
        :return: bool
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('async_req'):
            return self.notes_authorization_has_acces_with_http_info(itembase_id, user_or_group_id, **kwargs)  # noqa: E501
        else:
            (data) = self.notes_authorization_has_acces_with_http_info(itembase_id, user_or_group_id, **kwargs)  # noqa: E501
            return data

    def notes_authorization_has_acces_with_http_info(self, itembase_id, user_or_group_id, **kwargs):  # noqa: E501
        """Returns true if the user or group has access to the event or car  # noqa: E501

        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.notes_authorization_has_acces_with_http_info(itembase_id, user_or_group_id, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str itembase_id: Unique Id corresponding to an Event or a Car (required)
        :param str user_or_group_id: Unique Id corresponding to a User or a Group (required)
        :return: bool
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = ['itembase_id', 'user_or_group_id']  # 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 notes_authorization_has_acces" % key
                )
            params[key] = val
        del params['kwargs']
        # verify the required parameter 'itembase_id' is set
        if self.api_client.client_side_validation and ('itembase_id' not in params or
                                                       params['itembase_id'] is None):  # noqa: E501
            raise ValueError("Missing the required parameter `itembase_id` when calling `notes_authorization_has_acces`")  # noqa: E501
        # verify the required parameter 'user_or_group_id' is set
        if self.api_client.client_side_validation and ('user_or_group_id' not in params or
                                                       params['user_or_group_id'] is None):  # noqa: E501
            raise ValueError("Missing the required parameter `user_or_group_id` when calling `notes_authorization_has_acces`")  # noqa: E501

        collection_formats = {}

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

        query_params = []
        if 'user_or_group_id' in params:
            query_params.append(('userOrGroupId', params['user_or_group_id']))  # noqa: E501

        header_params = {}

        form_params = []
        local_var_files = {}

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

        # Authentication setting
        auth_settings = []  # noqa: E501

        return self.api_client.call_api(
            '/teamdbapi/v2.0/itembase/{itembaseId}/hasacces', 'GET',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='bool',  # 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 notes_authorization_set_notes_authorizations(self, authorization, **kwargs):  # noqa: E501
        """[Command] Set an authorization to a user or a group for an event or a car.  To give acces to a user or group you have to fill the ConcernedEntityId (user or group Id), ConcernedEntityIsGroup (true if group), ItembaseId (event or car id) and set HasAccess to true.  To remove the access to a user or group you have to fill the Id (the existing authorization unique id), ConcernedEntityId (user or group Id), ConcernedEntityIsGroup (true if group), ItembaseId (event or car id) and set HasAccess to false.  Notice : you have to load the event or car data before to set the authorization. Event or car data must be loaded locally first to any action.  # noqa: E501

        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.notes_authorization_set_notes_authorizations(authorization, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param NotesAuthorization authorization: The authorization to set (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.notes_authorization_set_notes_authorizations_with_http_info(authorization, **kwargs)  # noqa: E501
        else:
            (data) = self.notes_authorization_set_notes_authorizations_with_http_info(authorization, **kwargs)  # noqa: E501
            return data

    def notes_authorization_set_notes_authorizations_with_http_info(self, authorization, **kwargs):  # noqa: E501
        """[Command] Set an authorization to a user or a group for an event or a car.  To give acces to a user or group you have to fill the ConcernedEntityId (user or group Id), ConcernedEntityIsGroup (true if group), ItembaseId (event or car id) and set HasAccess to true.  To remove the access to a user or group you have to fill the Id (the existing authorization unique id), ConcernedEntityId (user or group Id), ConcernedEntityIsGroup (true if group), ItembaseId (event or car id) and set HasAccess to false.  Notice : you have to load the event or car data before to set the authorization. Event or car data must be loaded locally first to any action.  # noqa: E501

        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.notes_authorization_set_notes_authorizations_with_http_info(authorization, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param NotesAuthorization authorization: The authorization to set (required)
        :return: None
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = ['authorization']  # 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 notes_authorization_set_notes_authorizations" % key
                )
            params[key] = val
        del params['kwargs']
        # verify the required parameter 'authorization' is set
        if self.api_client.client_side_validation and ('authorization' not in params or
                                                       params['authorization'] is None):  # noqa: E501
            raise ValueError("Missing the required parameter `authorization` when calling `notes_authorization_set_notes_authorizations`")  # noqa: E501

        collection_formats = {}

        path_params = {}

        query_params = []

        header_params = {}

        form_params = []
        local_var_files = {}

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

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

        # Authentication setting
        auth_settings = []  # noqa: E501

        return self.api_client.call_api(
            '/teamdbapi/v2.0/notesauthorizations', 'POST',
            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)
