# coding: utf-8

"""
    CartoVista REST API

    No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)  # noqa: E501

    OpenAPI spec version: 2.0.0
    
    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 add_to_cartovista.swagger_client.api_client import ApiClient


class PortalApi(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 portal_cancel_upload(self, upload_id, tenant_url_code, **kwargs):  # noqa: E501
        """Cancels the file upload.  # noqa: E501

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

        :param async_req bool
        :param str upload_id: (required)
        :param str tenant_url_code: (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.portal_cancel_upload_with_http_info(upload_id, tenant_url_code, **kwargs)  # noqa: E501
        else:
            (data) = self.portal_cancel_upload_with_http_info(upload_id, tenant_url_code, **kwargs)  # noqa: E501
            return data

    def portal_cancel_upload_with_http_info(self, upload_id, tenant_url_code, **kwargs):  # noqa: E501
        """Cancels the file upload.  # noqa: E501

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

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

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

        collection_formats = {}

        path_params = {}
        if 'upload_id' in params:
            path_params['uploadId'] = params['upload_id']  # noqa: E501
        if 'tenant_url_code' in params:
            path_params['tenantUrlCode'] = params['tenant_url_code']  # 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 = ['apiKey', 'bearer', 'secretKey']  # noqa: E501

        return self.api_client.call_api(
            '/{tenantUrlCode}/api/v2/Portal/upload/{uploadId}/cancel', 'POST',
            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 portal_finalize_synchronous(self, body, upload_id, tenant_url_code, **kwargs):  # noqa: E501
        """Finalizes a data import with a file uploaded using `upload`.  # noqa: E501

        Unlike `upload/{uploadId}/finalize`, this call will return errors if there is a failure at any step of the upload and will wait until the end of the process to return 200.  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.portal_finalize_synchronous(body, upload_id, tenant_url_code, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param FinalizeUploadParameters body: (required)
        :param str upload_id: (required)
        :param str tenant_url_code: (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.portal_finalize_synchronous_with_http_info(body, upload_id, tenant_url_code, **kwargs)  # noqa: E501
        else:
            (data) = self.portal_finalize_synchronous_with_http_info(body, upload_id, tenant_url_code, **kwargs)  # noqa: E501
            return data

    def portal_finalize_synchronous_with_http_info(self, body, upload_id, tenant_url_code, **kwargs):  # noqa: E501
        """Finalizes a data import with a file uploaded using `upload`.  # noqa: E501

        Unlike `upload/{uploadId}/finalize`, this call will return errors if there is a failure at any step of the upload and will wait until the end of the process to return 200.  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.portal_finalize_synchronous_with_http_info(body, upload_id, tenant_url_code, async_req=True)
        >>> result = thread.get()

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

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

        collection_formats = {}

        path_params = {}
        if 'upload_id' in params:
            path_params['uploadId'] = params['upload_id']  # noqa: E501
        if 'tenant_url_code' in params:
            path_params['tenantUrlCode'] = params['tenant_url_code']  # noqa: E501

        query_params = []

        header_params = {}

        form_params = []
        local_var_files = {}

        body_params = None
        if 'body' in params:
            body_params = params['body']
        # 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 = ['apiKey', 'bearer', 'secretKey']  # noqa: E501

        return self.api_client.call_api(
            '/{tenantUrlCode}/api/v2/Portal/upload/{uploadId}/finalizeSynchronous', '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)

    def portal_finalize_upload(self, body, upload_id, tenant_url_code, **kwargs):  # noqa: E501
        """Finalizes a data import with a file uploaded using `upload`.  # noqa: E501

        Will return 200 if the upload is started succesfully, but there won't be any indication if there is a failure later on. To see errors that occur during the upload, use `upload/{uploadId}/finalizeSynchronous`.  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.portal_finalize_upload(body, upload_id, tenant_url_code, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param FinalizeUploadParameters body: (required)
        :param str upload_id: (required)
        :param str tenant_url_code: (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.portal_finalize_upload_with_http_info(body, upload_id, tenant_url_code, **kwargs)  # noqa: E501
        else:
            (data) = self.portal_finalize_upload_with_http_info(body, upload_id, tenant_url_code, **kwargs)  # noqa: E501
            return data

    def portal_finalize_upload_with_http_info(self, body, upload_id, tenant_url_code, **kwargs):  # noqa: E501
        """Finalizes a data import with a file uploaded using `upload`.  # noqa: E501

        Will return 200 if the upload is started succesfully, but there won't be any indication if there is a failure later on. To see errors that occur during the upload, use `upload/{uploadId}/finalizeSynchronous`.  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.portal_finalize_upload_with_http_info(body, upload_id, tenant_url_code, async_req=True)
        >>> result = thread.get()

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

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

        collection_formats = {}

        path_params = {}
        if 'upload_id' in params:
            path_params['uploadId'] = params['upload_id']  # noqa: E501
        if 'tenant_url_code' in params:
            path_params['tenantUrlCode'] = params['tenant_url_code']  # noqa: E501

        query_params = []

        header_params = {}

        form_params = []
        local_var_files = {}

        body_params = None
        if 'body' in params:
            body_params = params['body']
        # 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 = ['apiKey', 'bearer', 'secretKey']  # noqa: E501

        return self.api_client.call_api(
            '/{tenantUrlCode}/api/v2/Portal/upload/{uploadId}/finalize', '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)

    def portal_get_definition(self, upload_id, restrict_for, tenant_url_code, **kwargs):  # noqa: E501
        """Gets a description of the file's content.  # noqa: E501

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

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

    def portal_get_definition_with_http_info(self, upload_id, restrict_for, tenant_url_code, **kwargs):  # noqa: E501
        """Gets a description of the file's content.  # noqa: E501

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

        :param async_req bool
        :param str upload_id: (required)
        :param RestrictFor restrict_for: (required)
        :param str tenant_url_code: (required)
        :return: FileDescription
                 If the method is called asynchronously,
                 returns the request thread.
        """

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

        collection_formats = {}

        path_params = {}
        if 'upload_id' in params:
            path_params['uploadId'] = params['upload_id']  # noqa: E501
        if 'tenant_url_code' in params:
            path_params['tenantUrlCode'] = params['tenant_url_code']  # noqa: E501

        query_params = []
        if 'restrict_for' in params:
            query_params.append(('restrictFor', params['restrict_for']))  # 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'])  # noqa: E501

        # Authentication setting
        auth_settings = ['apiKey', 'bearer', 'secretKey']  # noqa: E501

        return self.api_client.call_api(
            '/{tenantUrlCode}/api/v2/Portal/upload/{uploadId}/definition', 'GET',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='FileDescription',  # 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 portal_get_subscription_and_user(self, tenant_url_code, **kwargs):  # noqa: E501
        """Gets the current user and the organization's subscription/license details.  # noqa: E501

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

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

    def portal_get_subscription_and_user_with_http_info(self, tenant_url_code, **kwargs):  # noqa: E501
        """Gets the current user and the organization's subscription/license details.  # noqa: E501

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

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

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

        collection_formats = {}

        path_params = {}
        if 'tenant_url_code' in params:
            path_params['tenantUrlCode'] = params['tenant_url_code']  # 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 = ['apiKey', 'bearer', 'secretKey']  # noqa: E501

        return self.api_client.call_api(
            '/{tenantUrlCode}/api/v2/Portal', 'GET',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='SubscriptionAndUser',  # 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 portal_upload(self, tenant_url_code, **kwargs):  # noqa: E501
        """Uploads a temporary file for layer use.  This will return an uploadId that can be used with /definition to get details on the file uploaded. Then use /finalize to complete the upload of the layer.  # noqa: E501

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

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

    def portal_upload_with_http_info(self, tenant_url_code, **kwargs):  # noqa: E501
        """Uploads a temporary file for layer use.  This will return an uploadId that can be used with /definition to get details on the file uploaded. Then use /finalize to complete the upload of the layer.  # noqa: E501

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

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

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

        collection_formats = {}

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

        query_params = []

        header_params = {}
        if 'upload_id' in params:
            header_params['uploadId'] = params['upload_id']  # noqa: E501

        form_params = []
        local_var_files = {}
        if 'file' in params:
            local_var_files['file'] = params['file']  # noqa: E501

        body_params = None
        # 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
            ['multipart/form-data'])  # noqa: E501

        # Authentication setting
        auth_settings = ['apiKey', 'bearer', 'secretKey']  # noqa: E501

        return self.api_client.call_api(
            '/{tenantUrlCode}/api/v2/Portal/upload', 'POST',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='str',  # 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)
