# coding: utf-8

"""
    Mentortools Marketplace Server

    Mentortools service for ingesting payment-provider webhooks into normalized order events

    The version of the OpenAPI document: 0.1.0
    Generated by OpenAPI Generator (https://openapi-generator.tech)

    Do not edit the class manually.
"""  # noqa: E501


import re  # noqa: F401
import io
import warnings

from pydantic import validate_arguments, ValidationError
from typing import overload, Optional, Union, Awaitable

from pydantic import StrictBool, StrictInt

from typing import Optional

from marketplace_server_connector.models.integration_in import IntegrationIn
from marketplace_server_connector.models.integration_patch_in import IntegrationPatchIn
from marketplace_server_connector.models.integration_test_in import IntegrationTestIn
from marketplace_server_connector.models.wrapped_response_id_out import WrappedResponseIdOut
from marketplace_server_connector.models.wrapped_response_integration_out import WrappedResponseIntegrationOut
from marketplace_server_connector.models.wrapped_response_integration_sync_out import WrappedResponseIntegrationSyncOut
from marketplace_server_connector.models.wrapped_response_integration_test_out import WrappedResponseIntegrationTestOut
from marketplace_server_connector.models.wrapped_response_list_integration_out import WrappedResponseListIntegrationOut
from marketplace_server_connector.models.wrapped_response_webhook_setup_out import WrappedResponseWebhookSetupOut

from marketplace_server_connector.api_client import ApiClient
from marketplace_server_connector.api_response import ApiResponse
from marketplace_server_connector.exceptions import (  # noqa: F401
    ApiTypeError,
    ApiValueError
)


class IntegrationsApi:
    """NOTE: This class is auto generated by OpenAPI Generator
    Ref: https://openapi-generator.tech

    Do not edit the class manually.
    """

    def __init__(self, api_client=None) -> None:
        if api_client is None:
            api_client = ApiClient.get_default()
        self.api_client = api_client

    @validate_arguments
    async def create_v1_integrations_post(self, integration_in : IntegrationIn, **kwargs) -> WrappedResponseIdOut:  # noqa: E501
        """Connect a provider integration  # noqa: E501

        For providers with a registration API (stripe, digistore, elopage, upgates) this also registers our webhook/IPN endpoint with the provider and stores the resulting verify secret; registration failure fails the connect with 400. Other providers: paste the webhook URL into the provider dashboard manually.  # noqa: E501

        :param integration_in: (required)
        :type integration_in: IntegrationIn
        :param _request_timeout: timeout setting for this request.
               If one number provided, it will be total request
               timeout. It can also be a pair (tuple) of
               (connection, read) timeouts.
        :return: Returns the result object.
                 If the method is called asynchronously,
                 returns the request thread.
        :rtype: WrappedResponseIdOut
        """
        kwargs['_return_http_data_only'] = True
        if '_preload_content' in kwargs:
            message = "Error! Please call the create_v1_integrations_post_with_http_info method with `_preload_content` instead and obtain raw data from ApiResponse.raw_data"  # noqa: E501
            raise ValueError(message)
        return await self.create_v1_integrations_post_with_http_info(integration_in, **kwargs)  # noqa: E501

    @validate_arguments
    async def create_v1_integrations_post_with_http_info(self, integration_in : IntegrationIn, **kwargs) -> ApiResponse:  # noqa: E501
        """Connect a provider integration  # noqa: E501

        For providers with a registration API (stripe, digistore, elopage, upgates) this also registers our webhook/IPN endpoint with the provider and stores the resulting verify secret; registration failure fails the connect with 400. Other providers: paste the webhook URL into the provider dashboard manually.  # noqa: E501

        :param integration_in: (required)
        :type integration_in: IntegrationIn
        :param _preload_content: if False, the ApiResponse.data will
                                 be set to none and raw_data will store the
                                 HTTP response body without reading/decoding.
                                 Default is True.
        :type _preload_content: bool, optional
        :param _return_http_data_only: response data instead of ApiResponse
                                       object with status code, headers, etc
        :type _return_http_data_only: bool, optional
        :param _request_timeout: timeout setting for this request. If one
                                 number provided, it will be total request
                                 timeout. It can also be a pair (tuple) of
                                 (connection, read) timeouts.
        :param _request_auth: set to override the auth_settings for an a single
                              request; this effectively ignores the authentication
                              in the spec for a single request.
        :type _request_auth: dict, optional
        :type _content_type: string, optional: force content-type for the request
        :return: Returns the result object.
                 If the method is called asynchronously,
                 returns the request thread.
        :rtype: tuple(WrappedResponseIdOut, status_code(int), headers(HTTPHeaderDict))
        """

        _params = locals()

        _all_params = [
            'integration_in'
        ]
        _all_params.extend(
            [
                '_return_http_data_only',
                '_preload_content',
                '_request_timeout',
                '_request_auth',
                '_content_type',
                '_headers'
            ]
        )

        # validate the arguments
        for _key, _val in _params['kwargs'].items():
            if _key not in _all_params:
                raise ApiTypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method create_v1_integrations_post" % _key
                )
            _params[_key] = _val
        del _params['kwargs']

        _collection_formats = {}

        # process the path parameters
        _path_params = {}

        # process the query parameters
        _query_params = []
        # process the header parameters
        _header_params = dict(_params.get('_headers', {}))
        # process the form parameters
        _form_params = []
        _files = {}
        # process the body parameter
        _body_params = None
        if _params['integration_in'] is not None:
            _body_params = _params['integration_in']

        # set the HTTP header `Accept`
        _header_params['Accept'] = self.api_client.select_header_accept(
            ['application/json'])  # noqa: E501

        # set the HTTP header `Content-Type`
        _content_types_list = _params.get('_content_type',
            self.api_client.select_header_content_type(
                ['application/json']))
        if _content_types_list:
                _header_params['Content-Type'] = _content_types_list

        # authentication setting
        _auth_settings = ['Bearer Authorization', 'ServerName Authorization']  # noqa: E501

        _response_types_map = {
            '200': "WrappedResponseIdOut",
            '422': "HTTPValidationError",
        }

        return await self.api_client.call_api(
            '/v1/integrations', 'POST',
            _path_params,
            _query_params,
            _header_params,
            body=_body_params,
            post_params=_form_params,
            files=_files,
            response_types_map=_response_types_map,
            auth_settings=_auth_settings,
            _return_http_data_only=_params.get('_return_http_data_only'),  # noqa: E501
            _preload_content=_params.get('_preload_content', True),
            _request_timeout=_params.get('_request_timeout'),
            collection_formats=_collection_formats,
            _request_auth=_params.get('_request_auth'))

    @validate_arguments
    async def delete_integration_v1_integrations_integration_id_delete(self, integration_id : StrictInt, **kwargs) -> WrappedResponseIdOut:  # noqa: E501
        """Disconnect (delete) an integration  # noqa: E501

        409 if the integration still has products (they back access-package links) — disable it (is_active=false) or remove its products first.  # noqa: E501

        :param integration_id: (required)
        :type integration_id: int
        :param _request_timeout: timeout setting for this request.
               If one number provided, it will be total request
               timeout. It can also be a pair (tuple) of
               (connection, read) timeouts.
        :return: Returns the result object.
                 If the method is called asynchronously,
                 returns the request thread.
        :rtype: WrappedResponseIdOut
        """
        kwargs['_return_http_data_only'] = True
        if '_preload_content' in kwargs:
            message = "Error! Please call the delete_integration_v1_integrations_integration_id_delete_with_http_info method with `_preload_content` instead and obtain raw data from ApiResponse.raw_data"  # noqa: E501
            raise ValueError(message)
        return await self.delete_integration_v1_integrations_integration_id_delete_with_http_info(integration_id, **kwargs)  # noqa: E501

    @validate_arguments
    async def delete_integration_v1_integrations_integration_id_delete_with_http_info(self, integration_id : StrictInt, **kwargs) -> ApiResponse:  # noqa: E501
        """Disconnect (delete) an integration  # noqa: E501

        409 if the integration still has products (they back access-package links) — disable it (is_active=false) or remove its products first.  # noqa: E501

        :param integration_id: (required)
        :type integration_id: int
        :param _preload_content: if False, the ApiResponse.data will
                                 be set to none and raw_data will store the
                                 HTTP response body without reading/decoding.
                                 Default is True.
        :type _preload_content: bool, optional
        :param _return_http_data_only: response data instead of ApiResponse
                                       object with status code, headers, etc
        :type _return_http_data_only: bool, optional
        :param _request_timeout: timeout setting for this request. If one
                                 number provided, it will be total request
                                 timeout. It can also be a pair (tuple) of
                                 (connection, read) timeouts.
        :param _request_auth: set to override the auth_settings for an a single
                              request; this effectively ignores the authentication
                              in the spec for a single request.
        :type _request_auth: dict, optional
        :type _content_type: string, optional: force content-type for the request
        :return: Returns the result object.
                 If the method is called asynchronously,
                 returns the request thread.
        :rtype: tuple(WrappedResponseIdOut, status_code(int), headers(HTTPHeaderDict))
        """

        _params = locals()

        _all_params = [
            'integration_id'
        ]
        _all_params.extend(
            [
                '_return_http_data_only',
                '_preload_content',
                '_request_timeout',
                '_request_auth',
                '_content_type',
                '_headers'
            ]
        )

        # validate the arguments
        for _key, _val in _params['kwargs'].items():
            if _key not in _all_params:
                raise ApiTypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method delete_integration_v1_integrations_integration_id_delete" % _key
                )
            _params[_key] = _val
        del _params['kwargs']

        _collection_formats = {}

        # process the path parameters
        _path_params = {}
        if _params['integration_id'] is not None:
            _path_params['integration_id'] = _params['integration_id']


        # process the query parameters
        _query_params = []
        # process the header parameters
        _header_params = dict(_params.get('_headers', {}))
        # process the form parameters
        _form_params = []
        _files = {}
        # process the body parameter
        _body_params = None
        # set the HTTP header `Accept`
        _header_params['Accept'] = self.api_client.select_header_accept(
            ['application/json'])  # noqa: E501

        # authentication setting
        _auth_settings = ['Bearer Authorization', 'ServerName Authorization']  # noqa: E501

        _response_types_map = {
            '200': "WrappedResponseIdOut",
            '422': "HTTPValidationError",
        }

        return await self.api_client.call_api(
            '/v1/integrations/{integration_id}', 'DELETE',
            _path_params,
            _query_params,
            _header_params,
            body=_body_params,
            post_params=_form_params,
            files=_files,
            response_types_map=_response_types_map,
            auth_settings=_auth_settings,
            _return_http_data_only=_params.get('_return_http_data_only'),  # noqa: E501
            _preload_content=_params.get('_preload_content', True),
            _request_timeout=_params.get('_request_timeout'),
            collection_formats=_collection_formats,
            _request_auth=_params.get('_request_auth'))

    @validate_arguments
    async def get_integration_v1_integrations_integration_id_get(self, integration_id : StrictInt, **kwargs) -> WrappedResponseIntegrationOut:  # noqa: E501
        """Get one integration  # noqa: E501


        :param integration_id: (required)
        :type integration_id: int
        :param _request_timeout: timeout setting for this request.
               If one number provided, it will be total request
               timeout. It can also be a pair (tuple) of
               (connection, read) timeouts.
        :return: Returns the result object.
                 If the method is called asynchronously,
                 returns the request thread.
        :rtype: WrappedResponseIntegrationOut
        """
        kwargs['_return_http_data_only'] = True
        if '_preload_content' in kwargs:
            message = "Error! Please call the get_integration_v1_integrations_integration_id_get_with_http_info method with `_preload_content` instead and obtain raw data from ApiResponse.raw_data"  # noqa: E501
            raise ValueError(message)
        return await self.get_integration_v1_integrations_integration_id_get_with_http_info(integration_id, **kwargs)  # noqa: E501

    @validate_arguments
    async def get_integration_v1_integrations_integration_id_get_with_http_info(self, integration_id : StrictInt, **kwargs) -> ApiResponse:  # noqa: E501
        """Get one integration  # noqa: E501


        :param integration_id: (required)
        :type integration_id: int
        :param _preload_content: if False, the ApiResponse.data will
                                 be set to none and raw_data will store the
                                 HTTP response body without reading/decoding.
                                 Default is True.
        :type _preload_content: bool, optional
        :param _return_http_data_only: response data instead of ApiResponse
                                       object with status code, headers, etc
        :type _return_http_data_only: bool, optional
        :param _request_timeout: timeout setting for this request. If one
                                 number provided, it will be total request
                                 timeout. It can also be a pair (tuple) of
                                 (connection, read) timeouts.
        :param _request_auth: set to override the auth_settings for an a single
                              request; this effectively ignores the authentication
                              in the spec for a single request.
        :type _request_auth: dict, optional
        :type _content_type: string, optional: force content-type for the request
        :return: Returns the result object.
                 If the method is called asynchronously,
                 returns the request thread.
        :rtype: tuple(WrappedResponseIntegrationOut, status_code(int), headers(HTTPHeaderDict))
        """

        _params = locals()

        _all_params = [
            'integration_id'
        ]
        _all_params.extend(
            [
                '_return_http_data_only',
                '_preload_content',
                '_request_timeout',
                '_request_auth',
                '_content_type',
                '_headers'
            ]
        )

        # validate the arguments
        for _key, _val in _params['kwargs'].items():
            if _key not in _all_params:
                raise ApiTypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method get_integration_v1_integrations_integration_id_get" % _key
                )
            _params[_key] = _val
        del _params['kwargs']

        _collection_formats = {}

        # process the path parameters
        _path_params = {}
        if _params['integration_id'] is not None:
            _path_params['integration_id'] = _params['integration_id']


        # process the query parameters
        _query_params = []
        # process the header parameters
        _header_params = dict(_params.get('_headers', {}))
        # process the form parameters
        _form_params = []
        _files = {}
        # process the body parameter
        _body_params = None
        # set the HTTP header `Accept`
        _header_params['Accept'] = self.api_client.select_header_accept(
            ['application/json'])  # noqa: E501

        # authentication setting
        _auth_settings = ['Bearer Authorization', 'ServerName Authorization']  # noqa: E501

        _response_types_map = {
            '200': "WrappedResponseIntegrationOut",
            '422': "HTTPValidationError",
        }

        return await self.api_client.call_api(
            '/v1/integrations/{integration_id}', 'GET',
            _path_params,
            _query_params,
            _header_params,
            body=_body_params,
            post_params=_form_params,
            files=_files,
            response_types_map=_response_types_map,
            auth_settings=_auth_settings,
            _return_http_data_only=_params.get('_return_http_data_only'),  # noqa: E501
            _preload_content=_params.get('_preload_content', True),
            _request_timeout=_params.get('_request_timeout'),
            collection_formats=_collection_formats,
            _request_auth=_params.get('_request_auth'))

    @validate_arguments
    async def list_integrations_v1_integrations_get(self, active_only : Optional[StrictBool] = None, **kwargs) -> WrappedResponseListIntegrationOut:  # noqa: E501
        """List the portal's provider integrations  # noqa: E501

        Query: active_only? (default false — includes disabled). Credentials are never returned; only the credential key names that are set.  # noqa: E501

        :param active_only:
        :type active_only: bool
        :param _request_timeout: timeout setting for this request.
               If one number provided, it will be total request
               timeout. It can also be a pair (tuple) of
               (connection, read) timeouts.
        :return: Returns the result object.
                 If the method is called asynchronously,
                 returns the request thread.
        :rtype: WrappedResponseListIntegrationOut
        """
        kwargs['_return_http_data_only'] = True
        if '_preload_content' in kwargs:
            message = "Error! Please call the list_integrations_v1_integrations_get_with_http_info method with `_preload_content` instead and obtain raw data from ApiResponse.raw_data"  # noqa: E501
            raise ValueError(message)
        return await self.list_integrations_v1_integrations_get_with_http_info(active_only, **kwargs)  # noqa: E501

    @validate_arguments
    async def list_integrations_v1_integrations_get_with_http_info(self, active_only : Optional[StrictBool] = None, **kwargs) -> ApiResponse:  # noqa: E501
        """List the portal's provider integrations  # noqa: E501

        Query: active_only? (default false — includes disabled). Credentials are never returned; only the credential key names that are set.  # noqa: E501

        :param active_only:
        :type active_only: bool
        :param _preload_content: if False, the ApiResponse.data will
                                 be set to none and raw_data will store the
                                 HTTP response body without reading/decoding.
                                 Default is True.
        :type _preload_content: bool, optional
        :param _return_http_data_only: response data instead of ApiResponse
                                       object with status code, headers, etc
        :type _return_http_data_only: bool, optional
        :param _request_timeout: timeout setting for this request. If one
                                 number provided, it will be total request
                                 timeout. It can also be a pair (tuple) of
                                 (connection, read) timeouts.
        :param _request_auth: set to override the auth_settings for an a single
                              request; this effectively ignores the authentication
                              in the spec for a single request.
        :type _request_auth: dict, optional
        :type _content_type: string, optional: force content-type for the request
        :return: Returns the result object.
                 If the method is called asynchronously,
                 returns the request thread.
        :rtype: tuple(WrappedResponseListIntegrationOut, status_code(int), headers(HTTPHeaderDict))
        """

        _params = locals()

        _all_params = [
            'active_only'
        ]
        _all_params.extend(
            [
                '_return_http_data_only',
                '_preload_content',
                '_request_timeout',
                '_request_auth',
                '_content_type',
                '_headers'
            ]
        )

        # validate the arguments
        for _key, _val in _params['kwargs'].items():
            if _key not in _all_params:
                raise ApiTypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method list_integrations_v1_integrations_get" % _key
                )
            _params[_key] = _val
        del _params['kwargs']

        _collection_formats = {}

        # process the path parameters
        _path_params = {}

        # process the query parameters
        _query_params = []
        if _params.get('active_only') is not None:  # noqa: E501
            _query_params.append(('active_only', _params['active_only']))

        # process the header parameters
        _header_params = dict(_params.get('_headers', {}))
        # process the form parameters
        _form_params = []
        _files = {}
        # process the body parameter
        _body_params = None
        # set the HTTP header `Accept`
        _header_params['Accept'] = self.api_client.select_header_accept(
            ['application/json'])  # noqa: E501

        # authentication setting
        _auth_settings = ['Bearer Authorization', 'ServerName Authorization']  # noqa: E501

        _response_types_map = {
            '200': "WrappedResponseListIntegrationOut",
            '422': "HTTPValidationError",
        }

        return await self.api_client.call_api(
            '/v1/integrations', 'GET',
            _path_params,
            _query_params,
            _header_params,
            body=_body_params,
            post_params=_form_params,
            files=_files,
            response_types_map=_response_types_map,
            auth_settings=_auth_settings,
            _return_http_data_only=_params.get('_return_http_data_only'),  # noqa: E501
            _preload_content=_params.get('_preload_content', True),
            _request_timeout=_params.get('_request_timeout'),
            collection_formats=_collection_formats,
            _request_auth=_params.get('_request_auth'))

    @validate_arguments
    async def setup_webhooks_v1_integrations_integration_id_webhooks_setup_post(self, integration_id : StrictInt, **kwargs) -> WrappedResponseWebhookSetupOut:  # noqa: E501
        """(Re-)register the provider-side webhook  # noqa: E501

        Points the provider's webhook/IPN at our endpoint using the STORED credentials (registration also runs automatically on connect and credential rotation). Use to re-sync after a provider-side deletion. supported=false => manual dashboard setup for this provider.  # noqa: E501

        :param integration_id: (required)
        :type integration_id: int
        :param _request_timeout: timeout setting for this request.
               If one number provided, it will be total request
               timeout. It can also be a pair (tuple) of
               (connection, read) timeouts.
        :return: Returns the result object.
                 If the method is called asynchronously,
                 returns the request thread.
        :rtype: WrappedResponseWebhookSetupOut
        """
        kwargs['_return_http_data_only'] = True
        if '_preload_content' in kwargs:
            message = "Error! Please call the setup_webhooks_v1_integrations_integration_id_webhooks_setup_post_with_http_info method with `_preload_content` instead and obtain raw data from ApiResponse.raw_data"  # noqa: E501
            raise ValueError(message)
        return await self.setup_webhooks_v1_integrations_integration_id_webhooks_setup_post_with_http_info(integration_id, **kwargs)  # noqa: E501

    @validate_arguments
    async def setup_webhooks_v1_integrations_integration_id_webhooks_setup_post_with_http_info(self, integration_id : StrictInt, **kwargs) -> ApiResponse:  # noqa: E501
        """(Re-)register the provider-side webhook  # noqa: E501

        Points the provider's webhook/IPN at our endpoint using the STORED credentials (registration also runs automatically on connect and credential rotation). Use to re-sync after a provider-side deletion. supported=false => manual dashboard setup for this provider.  # noqa: E501

        :param integration_id: (required)
        :type integration_id: int
        :param _preload_content: if False, the ApiResponse.data will
                                 be set to none and raw_data will store the
                                 HTTP response body without reading/decoding.
                                 Default is True.
        :type _preload_content: bool, optional
        :param _return_http_data_only: response data instead of ApiResponse
                                       object with status code, headers, etc
        :type _return_http_data_only: bool, optional
        :param _request_timeout: timeout setting for this request. If one
                                 number provided, it will be total request
                                 timeout. It can also be a pair (tuple) of
                                 (connection, read) timeouts.
        :param _request_auth: set to override the auth_settings for an a single
                              request; this effectively ignores the authentication
                              in the spec for a single request.
        :type _request_auth: dict, optional
        :type _content_type: string, optional: force content-type for the request
        :return: Returns the result object.
                 If the method is called asynchronously,
                 returns the request thread.
        :rtype: tuple(WrappedResponseWebhookSetupOut, status_code(int), headers(HTTPHeaderDict))
        """

        _params = locals()

        _all_params = [
            'integration_id'
        ]
        _all_params.extend(
            [
                '_return_http_data_only',
                '_preload_content',
                '_request_timeout',
                '_request_auth',
                '_content_type',
                '_headers'
            ]
        )

        # validate the arguments
        for _key, _val in _params['kwargs'].items():
            if _key not in _all_params:
                raise ApiTypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method setup_webhooks_v1_integrations_integration_id_webhooks_setup_post" % _key
                )
            _params[_key] = _val
        del _params['kwargs']

        _collection_formats = {}

        # process the path parameters
        _path_params = {}
        if _params['integration_id'] is not None:
            _path_params['integration_id'] = _params['integration_id']


        # process the query parameters
        _query_params = []
        # process the header parameters
        _header_params = dict(_params.get('_headers', {}))
        # process the form parameters
        _form_params = []
        _files = {}
        # process the body parameter
        _body_params = None
        # set the HTTP header `Accept`
        _header_params['Accept'] = self.api_client.select_header_accept(
            ['application/json'])  # noqa: E501

        # authentication setting
        _auth_settings = ['Bearer Authorization', 'ServerName Authorization']  # noqa: E501

        _response_types_map = {
            '200': "WrappedResponseWebhookSetupOut",
            '422': "HTTPValidationError",
        }

        return await self.api_client.call_api(
            '/v1/integrations/{integration_id}/webhooks/setup', 'POST',
            _path_params,
            _query_params,
            _header_params,
            body=_body_params,
            post_params=_form_params,
            files=_files,
            response_types_map=_response_types_map,
            auth_settings=_auth_settings,
            _return_http_data_only=_params.get('_return_http_data_only'),  # noqa: E501
            _preload_content=_params.get('_preload_content', True),
            _request_timeout=_params.get('_request_timeout'),
            collection_formats=_collection_formats,
            _request_auth=_params.get('_request_auth'))

    @validate_arguments
    async def sync_products_v1_integrations_integration_id_products_sync_post(self, integration_id : StrictInt, **kwargs) -> WrappedResponseIntegrationSyncOut:  # noqa: E501
        """Sync products from one integration's provider  # noqa: E501


        :param integration_id: (required)
        :type integration_id: int
        :param _request_timeout: timeout setting for this request.
               If one number provided, it will be total request
               timeout. It can also be a pair (tuple) of
               (connection, read) timeouts.
        :return: Returns the result object.
                 If the method is called asynchronously,
                 returns the request thread.
        :rtype: WrappedResponseIntegrationSyncOut
        """
        kwargs['_return_http_data_only'] = True
        if '_preload_content' in kwargs:
            message = "Error! Please call the sync_products_v1_integrations_integration_id_products_sync_post_with_http_info method with `_preload_content` instead and obtain raw data from ApiResponse.raw_data"  # noqa: E501
            raise ValueError(message)
        return await self.sync_products_v1_integrations_integration_id_products_sync_post_with_http_info(integration_id, **kwargs)  # noqa: E501

    @validate_arguments
    async def sync_products_v1_integrations_integration_id_products_sync_post_with_http_info(self, integration_id : StrictInt, **kwargs) -> ApiResponse:  # noqa: E501
        """Sync products from one integration's provider  # noqa: E501


        :param integration_id: (required)
        :type integration_id: int
        :param _preload_content: if False, the ApiResponse.data will
                                 be set to none and raw_data will store the
                                 HTTP response body without reading/decoding.
                                 Default is True.
        :type _preload_content: bool, optional
        :param _return_http_data_only: response data instead of ApiResponse
                                       object with status code, headers, etc
        :type _return_http_data_only: bool, optional
        :param _request_timeout: timeout setting for this request. If one
                                 number provided, it will be total request
                                 timeout. It can also be a pair (tuple) of
                                 (connection, read) timeouts.
        :param _request_auth: set to override the auth_settings for an a single
                              request; this effectively ignores the authentication
                              in the spec for a single request.
        :type _request_auth: dict, optional
        :type _content_type: string, optional: force content-type for the request
        :return: Returns the result object.
                 If the method is called asynchronously,
                 returns the request thread.
        :rtype: tuple(WrappedResponseIntegrationSyncOut, status_code(int), headers(HTTPHeaderDict))
        """

        _params = locals()

        _all_params = [
            'integration_id'
        ]
        _all_params.extend(
            [
                '_return_http_data_only',
                '_preload_content',
                '_request_timeout',
                '_request_auth',
                '_content_type',
                '_headers'
            ]
        )

        # validate the arguments
        for _key, _val in _params['kwargs'].items():
            if _key not in _all_params:
                raise ApiTypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method sync_products_v1_integrations_integration_id_products_sync_post" % _key
                )
            _params[_key] = _val
        del _params['kwargs']

        _collection_formats = {}

        # process the path parameters
        _path_params = {}
        if _params['integration_id'] is not None:
            _path_params['integration_id'] = _params['integration_id']


        # process the query parameters
        _query_params = []
        # process the header parameters
        _header_params = dict(_params.get('_headers', {}))
        # process the form parameters
        _form_params = []
        _files = {}
        # process the body parameter
        _body_params = None
        # set the HTTP header `Accept`
        _header_params['Accept'] = self.api_client.select_header_accept(
            ['application/json'])  # noqa: E501

        # authentication setting
        _auth_settings = ['Bearer Authorization', 'ServerName Authorization']  # noqa: E501

        _response_types_map = {
            '200': "WrappedResponseIntegrationSyncOut",
            '422': "HTTPValidationError",
        }

        return await self.api_client.call_api(
            '/v1/integrations/{integration_id}/products/sync', 'POST',
            _path_params,
            _query_params,
            _header_params,
            body=_body_params,
            post_params=_form_params,
            files=_files,
            response_types_map=_response_types_map,
            auth_settings=_auth_settings,
            _return_http_data_only=_params.get('_return_http_data_only'),  # noqa: E501
            _preload_content=_params.get('_preload_content', True),
            _request_timeout=_params.get('_request_timeout'),
            collection_formats=_collection_formats,
            _request_auth=_params.get('_request_auth'))

    @validate_arguments
    async def test_credentials_v1_integrations_test_post(self, integration_test_in : IntegrationTestIn, **kwargs) -> WrappedResponseIntegrationTestOut:  # noqa: E501
        """Test provider credentials (before saving)  # noqa: E501

        Body: {provider, credentials}. Validates the credentials against the provider's API without saving anything — for the connect/edit forms. Providers without a testable API return supported=false. To re-check an already-saved connection use POST /{id}/test.  # noqa: E501

        :param integration_test_in: (required)
        :type integration_test_in: IntegrationTestIn
        :param _request_timeout: timeout setting for this request.
               If one number provided, it will be total request
               timeout. It can also be a pair (tuple) of
               (connection, read) timeouts.
        :return: Returns the result object.
                 If the method is called asynchronously,
                 returns the request thread.
        :rtype: WrappedResponseIntegrationTestOut
        """
        kwargs['_return_http_data_only'] = True
        if '_preload_content' in kwargs:
            message = "Error! Please call the test_credentials_v1_integrations_test_post_with_http_info method with `_preload_content` instead and obtain raw data from ApiResponse.raw_data"  # noqa: E501
            raise ValueError(message)
        return await self.test_credentials_v1_integrations_test_post_with_http_info(integration_test_in, **kwargs)  # noqa: E501

    @validate_arguments
    async def test_credentials_v1_integrations_test_post_with_http_info(self, integration_test_in : IntegrationTestIn, **kwargs) -> ApiResponse:  # noqa: E501
        """Test provider credentials (before saving)  # noqa: E501

        Body: {provider, credentials}. Validates the credentials against the provider's API without saving anything — for the connect/edit forms. Providers without a testable API return supported=false. To re-check an already-saved connection use POST /{id}/test.  # noqa: E501

        :param integration_test_in: (required)
        :type integration_test_in: IntegrationTestIn
        :param _preload_content: if False, the ApiResponse.data will
                                 be set to none and raw_data will store the
                                 HTTP response body without reading/decoding.
                                 Default is True.
        :type _preload_content: bool, optional
        :param _return_http_data_only: response data instead of ApiResponse
                                       object with status code, headers, etc
        :type _return_http_data_only: bool, optional
        :param _request_timeout: timeout setting for this request. If one
                                 number provided, it will be total request
                                 timeout. It can also be a pair (tuple) of
                                 (connection, read) timeouts.
        :param _request_auth: set to override the auth_settings for an a single
                              request; this effectively ignores the authentication
                              in the spec for a single request.
        :type _request_auth: dict, optional
        :type _content_type: string, optional: force content-type for the request
        :return: Returns the result object.
                 If the method is called asynchronously,
                 returns the request thread.
        :rtype: tuple(WrappedResponseIntegrationTestOut, status_code(int), headers(HTTPHeaderDict))
        """

        _params = locals()

        _all_params = [
            'integration_test_in'
        ]
        _all_params.extend(
            [
                '_return_http_data_only',
                '_preload_content',
                '_request_timeout',
                '_request_auth',
                '_content_type',
                '_headers'
            ]
        )

        # validate the arguments
        for _key, _val in _params['kwargs'].items():
            if _key not in _all_params:
                raise ApiTypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method test_credentials_v1_integrations_test_post" % _key
                )
            _params[_key] = _val
        del _params['kwargs']

        _collection_formats = {}

        # process the path parameters
        _path_params = {}

        # process the query parameters
        _query_params = []
        # process the header parameters
        _header_params = dict(_params.get('_headers', {}))
        # process the form parameters
        _form_params = []
        _files = {}
        # process the body parameter
        _body_params = None
        if _params['integration_test_in'] is not None:
            _body_params = _params['integration_test_in']

        # set the HTTP header `Accept`
        _header_params['Accept'] = self.api_client.select_header_accept(
            ['application/json'])  # noqa: E501

        # set the HTTP header `Content-Type`
        _content_types_list = _params.get('_content_type',
            self.api_client.select_header_content_type(
                ['application/json']))
        if _content_types_list:
                _header_params['Content-Type'] = _content_types_list

        # authentication setting
        _auth_settings = ['Bearer Authorization', 'ServerName Authorization']  # noqa: E501

        _response_types_map = {
            '200': "WrappedResponseIntegrationTestOut",
            '422': "HTTPValidationError",
        }

        return await self.api_client.call_api(
            '/v1/integrations/test', 'POST',
            _path_params,
            _query_params,
            _header_params,
            body=_body_params,
            post_params=_form_params,
            files=_files,
            response_types_map=_response_types_map,
            auth_settings=_auth_settings,
            _return_http_data_only=_params.get('_return_http_data_only'),  # noqa: E501
            _preload_content=_params.get('_preload_content', True),
            _request_timeout=_params.get('_request_timeout'),
            collection_formats=_collection_formats,
            _request_auth=_params.get('_request_auth'))

    @validate_arguments
    async def test_integration_v1_integrations_integration_id_test_post(self, integration_id : StrictInt, **kwargs) -> WrappedResponseIntegrationTestOut:  # noqa: E501
        """Test an integration's saved connection  # noqa: E501

        No body. Re-checks the STORED credentials against the provider — credentials are write-only, so this is the only way to test an existing connection.  # noqa: E501

        :param integration_id: (required)
        :type integration_id: int
        :param _request_timeout: timeout setting for this request.
               If one number provided, it will be total request
               timeout. It can also be a pair (tuple) of
               (connection, read) timeouts.
        :return: Returns the result object.
                 If the method is called asynchronously,
                 returns the request thread.
        :rtype: WrappedResponseIntegrationTestOut
        """
        kwargs['_return_http_data_only'] = True
        if '_preload_content' in kwargs:
            message = "Error! Please call the test_integration_v1_integrations_integration_id_test_post_with_http_info method with `_preload_content` instead and obtain raw data from ApiResponse.raw_data"  # noqa: E501
            raise ValueError(message)
        return await self.test_integration_v1_integrations_integration_id_test_post_with_http_info(integration_id, **kwargs)  # noqa: E501

    @validate_arguments
    async def test_integration_v1_integrations_integration_id_test_post_with_http_info(self, integration_id : StrictInt, **kwargs) -> ApiResponse:  # noqa: E501
        """Test an integration's saved connection  # noqa: E501

        No body. Re-checks the STORED credentials against the provider — credentials are write-only, so this is the only way to test an existing connection.  # noqa: E501

        :param integration_id: (required)
        :type integration_id: int
        :param _preload_content: if False, the ApiResponse.data will
                                 be set to none and raw_data will store the
                                 HTTP response body without reading/decoding.
                                 Default is True.
        :type _preload_content: bool, optional
        :param _return_http_data_only: response data instead of ApiResponse
                                       object with status code, headers, etc
        :type _return_http_data_only: bool, optional
        :param _request_timeout: timeout setting for this request. If one
                                 number provided, it will be total request
                                 timeout. It can also be a pair (tuple) of
                                 (connection, read) timeouts.
        :param _request_auth: set to override the auth_settings for an a single
                              request; this effectively ignores the authentication
                              in the spec for a single request.
        :type _request_auth: dict, optional
        :type _content_type: string, optional: force content-type for the request
        :return: Returns the result object.
                 If the method is called asynchronously,
                 returns the request thread.
        :rtype: tuple(WrappedResponseIntegrationTestOut, status_code(int), headers(HTTPHeaderDict))
        """

        _params = locals()

        _all_params = [
            'integration_id'
        ]
        _all_params.extend(
            [
                '_return_http_data_only',
                '_preload_content',
                '_request_timeout',
                '_request_auth',
                '_content_type',
                '_headers'
            ]
        )

        # validate the arguments
        for _key, _val in _params['kwargs'].items():
            if _key not in _all_params:
                raise ApiTypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method test_integration_v1_integrations_integration_id_test_post" % _key
                )
            _params[_key] = _val
        del _params['kwargs']

        _collection_formats = {}

        # process the path parameters
        _path_params = {}
        if _params['integration_id'] is not None:
            _path_params['integration_id'] = _params['integration_id']


        # process the query parameters
        _query_params = []
        # process the header parameters
        _header_params = dict(_params.get('_headers', {}))
        # process the form parameters
        _form_params = []
        _files = {}
        # process the body parameter
        _body_params = None
        # set the HTTP header `Accept`
        _header_params['Accept'] = self.api_client.select_header_accept(
            ['application/json'])  # noqa: E501

        # authentication setting
        _auth_settings = ['Bearer Authorization', 'ServerName Authorization']  # noqa: E501

        _response_types_map = {
            '200': "WrappedResponseIntegrationTestOut",
            '422': "HTTPValidationError",
        }

        return await self.api_client.call_api(
            '/v1/integrations/{integration_id}/test', 'POST',
            _path_params,
            _query_params,
            _header_params,
            body=_body_params,
            post_params=_form_params,
            files=_files,
            response_types_map=_response_types_map,
            auth_settings=_auth_settings,
            _return_http_data_only=_params.get('_return_http_data_only'),  # noqa: E501
            _preload_content=_params.get('_preload_content', True),
            _request_timeout=_params.get('_request_timeout'),
            collection_formats=_collection_formats,
            _request_auth=_params.get('_request_auth'))

    @validate_arguments
    async def update_integration_v1_integrations_integration_id_patch(self, integration_id : StrictInt, integration_patch_in : IntegrationPatchIn, **kwargs) -> WrappedResponseIdOut:  # noqa: E501
        """Update an integration (rotate credentials / enable-disable)  # noqa: E501

        Body: {credentials?, is_active?, sync_enabled?}. credentials replaces the whole set and re-registers the provider webhook (rotating its verify secret) for auto-registered providers; is_active=false is the safe 'disconnect' (stops webhooks granting, keeps products); sync_enabled=false excludes it from sync-all (manual product curation).  # noqa: E501

        :param integration_id: (required)
        :type integration_id: int
        :param integration_patch_in: (required)
        :type integration_patch_in: IntegrationPatchIn
        :param _request_timeout: timeout setting for this request.
               If one number provided, it will be total request
               timeout. It can also be a pair (tuple) of
               (connection, read) timeouts.
        :return: Returns the result object.
                 If the method is called asynchronously,
                 returns the request thread.
        :rtype: WrappedResponseIdOut
        """
        kwargs['_return_http_data_only'] = True
        if '_preload_content' in kwargs:
            message = "Error! Please call the update_integration_v1_integrations_integration_id_patch_with_http_info method with `_preload_content` instead and obtain raw data from ApiResponse.raw_data"  # noqa: E501
            raise ValueError(message)
        return await self.update_integration_v1_integrations_integration_id_patch_with_http_info(integration_id, integration_patch_in, **kwargs)  # noqa: E501

    @validate_arguments
    async def update_integration_v1_integrations_integration_id_patch_with_http_info(self, integration_id : StrictInt, integration_patch_in : IntegrationPatchIn, **kwargs) -> ApiResponse:  # noqa: E501
        """Update an integration (rotate credentials / enable-disable)  # noqa: E501

        Body: {credentials?, is_active?, sync_enabled?}. credentials replaces the whole set and re-registers the provider webhook (rotating its verify secret) for auto-registered providers; is_active=false is the safe 'disconnect' (stops webhooks granting, keeps products); sync_enabled=false excludes it from sync-all (manual product curation).  # noqa: E501

        :param integration_id: (required)
        :type integration_id: int
        :param integration_patch_in: (required)
        :type integration_patch_in: IntegrationPatchIn
        :param _preload_content: if False, the ApiResponse.data will
                                 be set to none and raw_data will store the
                                 HTTP response body without reading/decoding.
                                 Default is True.
        :type _preload_content: bool, optional
        :param _return_http_data_only: response data instead of ApiResponse
                                       object with status code, headers, etc
        :type _return_http_data_only: bool, optional
        :param _request_timeout: timeout setting for this request. If one
                                 number provided, it will be total request
                                 timeout. It can also be a pair (tuple) of
                                 (connection, read) timeouts.
        :param _request_auth: set to override the auth_settings for an a single
                              request; this effectively ignores the authentication
                              in the spec for a single request.
        :type _request_auth: dict, optional
        :type _content_type: string, optional: force content-type for the request
        :return: Returns the result object.
                 If the method is called asynchronously,
                 returns the request thread.
        :rtype: tuple(WrappedResponseIdOut, status_code(int), headers(HTTPHeaderDict))
        """

        _params = locals()

        _all_params = [
            'integration_id',
            'integration_patch_in'
        ]
        _all_params.extend(
            [
                '_return_http_data_only',
                '_preload_content',
                '_request_timeout',
                '_request_auth',
                '_content_type',
                '_headers'
            ]
        )

        # validate the arguments
        for _key, _val in _params['kwargs'].items():
            if _key not in _all_params:
                raise ApiTypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method update_integration_v1_integrations_integration_id_patch" % _key
                )
            _params[_key] = _val
        del _params['kwargs']

        _collection_formats = {}

        # process the path parameters
        _path_params = {}
        if _params['integration_id'] is not None:
            _path_params['integration_id'] = _params['integration_id']


        # process the query parameters
        _query_params = []
        # process the header parameters
        _header_params = dict(_params.get('_headers', {}))
        # process the form parameters
        _form_params = []
        _files = {}
        # process the body parameter
        _body_params = None
        if _params['integration_patch_in'] is not None:
            _body_params = _params['integration_patch_in']

        # set the HTTP header `Accept`
        _header_params['Accept'] = self.api_client.select_header_accept(
            ['application/json'])  # noqa: E501

        # set the HTTP header `Content-Type`
        _content_types_list = _params.get('_content_type',
            self.api_client.select_header_content_type(
                ['application/json']))
        if _content_types_list:
                _header_params['Content-Type'] = _content_types_list

        # authentication setting
        _auth_settings = ['Bearer Authorization', 'ServerName Authorization']  # noqa: E501

        _response_types_map = {
            '200': "WrappedResponseIdOut",
            '422': "HTTPValidationError",
        }

        return await self.api_client.call_api(
            '/v1/integrations/{integration_id}', 'PATCH',
            _path_params,
            _query_params,
            _header_params,
            body=_body_params,
            post_params=_form_params,
            files=_files,
            response_types_map=_response_types_map,
            auth_settings=_auth_settings,
            _return_http_data_only=_params.get('_return_http_data_only'),  # noqa: E501
            _preload_content=_params.get('_preload_content', True),
            _request_timeout=_params.get('_request_timeout'),
            collection_formats=_collection_formats,
            _request_auth=_params.get('_request_auth'))
