# 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 VersionApi(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 version_create_version(self, created_version, **kwargs):  # noqa: E501
        """Create a new version by importing a definition file  # noqa: E501

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

        :param async_req bool
        :param Version created_version: The version to create. (required)
        :param str default_revision_name: The default name that will be given to the new revisions created during the file import. For example : Rev_000
        :param str assembly_name: The assembly name that will be created during the import.
        :param str copy_from_version: The version id used to copy the group. Set this argument to \"00000000-0000-0000-0000-000000000000\" if you don't want to make a copy.
        :param bool set_default_assembly: True to define the new assembly as the version's default assembly
        :return: Version
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('async_req'):
            return self.version_create_version_with_http_info(created_version, **kwargs)  # noqa: E501
        else:
            (data) = self.version_create_version_with_http_info(created_version, **kwargs)  # noqa: E501
            return data

    def version_create_version_with_http_info(self, created_version, **kwargs):  # noqa: E501
        """Create a new version by importing a definition file  # noqa: E501

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

        :param async_req bool
        :param Version created_version: The version to create. (required)
        :param str default_revision_name: The default name that will be given to the new revisions created during the file import. For example : Rev_000
        :param str assembly_name: The assembly name that will be created during the import.
        :param str copy_from_version: The version id used to copy the group. Set this argument to \"00000000-0000-0000-0000-000000000000\" if you don't want to make a copy.
        :param bool set_default_assembly: True to define the new assembly as the version's default assembly
        :return: Version
                 If the method is called asynchronously,
                 returns the request thread.
        """

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

        collection_formats = {}

        path_params = {}

        query_params = []
        if 'default_revision_name' in params:
            query_params.append(('defaultRevisionName', params['default_revision_name']))  # noqa: E501
        if 'assembly_name' in params:
            query_params.append(('assemblyName', params['assembly_name']))  # noqa: E501
        if 'copy_from_version' in params:
            query_params.append(('copyFromVersion', params['copy_from_version']))  # noqa: E501
        if 'set_default_assembly' in params:
            query_params.append(('setDefaultAssembly', params['set_default_assembly']))  # noqa: E501

        header_params = {}

        form_params = []
        local_var_files = {}

        body_params = None
        if 'created_version' in params:
            body_params = params['created_version']
        # 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/version', 'POST',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='Version',  # 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 version_get_version(self, version_id, **kwargs):  # noqa: E501
        """Get a version via a unique id.  # noqa: E501

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

        :param async_req bool
        :param str version_id: The unique version id to which you want to get the version (required)
        :return: Version
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('async_req'):
            return self.version_get_version_with_http_info(version_id, **kwargs)  # noqa: E501
        else:
            (data) = self.version_get_version_with_http_info(version_id, **kwargs)  # noqa: E501
            return data

    def version_get_version_with_http_info(self, version_id, **kwargs):  # noqa: E501
        """Get a version via a unique id.  # noqa: E501

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

        :param async_req bool
        :param str version_id: The unique version id to which you want to get the version (required)
        :return: Version
                 If the method is called asynchronously,
                 returns the request thread.
        """

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

        collection_formats = {}

        path_params = {}
        if 'version_id' in params:
            path_params['versionId'] = params['version_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/version/{versionId}', 'GET',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='Version',  # 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 version_get_versions(self, target_id, **kwargs):  # noqa: E501
        """Get the list of all versions for a given target  # noqa: E501

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

        :param async_req bool
        :param str target_id: The unique target id to wich you want to get the versions. (required)
        :return: list[Version]
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('async_req'):
            return self.version_get_versions_with_http_info(target_id, **kwargs)  # noqa: E501
        else:
            (data) = self.version_get_versions_with_http_info(target_id, **kwargs)  # noqa: E501
            return data

    def version_get_versions_with_http_info(self, target_id, **kwargs):  # noqa: E501
        """Get the list of all versions for a given target  # noqa: E501

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

        :param async_req bool
        :param str target_id: The unique target id to wich you want to get the versions. (required)
        :return: list[Version]
                 If the method is called asynchronously,
                 returns the request thread.
        """

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

        collection_formats = {}

        path_params = {}
        if 'target_id' in params:
            path_params['targetId'] = params['target_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/target/{targetId}/versions', 'GET',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='list[Version]',  # 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 version_update_version(self, version_id, updated_version, **kwargs):  # noqa: E501
        """Update an existing version  # noqa: E501

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

        :param async_req bool
        :param str version_id: The version id corresponding to the version you want to update. (required)
        :param Version updated_version: The version to update. (required)
        :return: Version
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('async_req'):
            return self.version_update_version_with_http_info(version_id, updated_version, **kwargs)  # noqa: E501
        else:
            (data) = self.version_update_version_with_http_info(version_id, updated_version, **kwargs)  # noqa: E501
            return data

    def version_update_version_with_http_info(self, version_id, updated_version, **kwargs):  # noqa: E501
        """Update an existing version  # noqa: E501

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

        :param async_req bool
        :param str version_id: The version id corresponding to the version you want to update. (required)
        :param Version updated_version: The version to update. (required)
        :return: Version
                 If the method is called asynchronously,
                 returns the request thread.
        """

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

        collection_formats = {}

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

        query_params = []

        header_params = {}

        form_params = []
        local_var_files = {}

        body_params = None
        if 'updated_version' in params:
            body_params = params['updated_version']
        # 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/version/{versionId}', 'PUT',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='Version',  # 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)
