# coding: utf-8

"""
    Mentortools Access Server

    Mentortools service for Access Packages with lazy access resolution

    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, StrictStr, conint

from typing import Optional

from access_server_connector.models.package_in import PackageIn
from access_server_connector.models.package_patch_in import PackagePatchIn
from access_server_connector.models.package_rule_in import PackageRuleIn
from access_server_connector.models.product_link_in import ProductLinkIn
from access_server_connector.models.wrapped_response_id_out import WrappedResponseIdOut
from access_server_connector.models.wrapped_response_int import WrappedResponseInt
from access_server_connector.models.wrapped_response_list_member_ownership_out import WrappedResponseListMemberOwnershipOut
from access_server_connector.models.wrapped_response_list_package_out import WrappedResponseListPackageOut
from access_server_connector.models.wrapped_response_list_product_link_out import WrappedResponseListProductLinkOut
from access_server_connector.models.wrapped_response_list_rule_out import WrappedResponseListRuleOut
from access_server_connector.models.wrapped_response_package_detail_out import WrappedResponsePackageDetailOut
from access_server_connector.models.wrapped_response_public_package_out import WrappedResponsePublicPackageOut

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


class PackagesApi:
    """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 count_members_v1_packages_access_package_id_members_count_get(self, access_package_id : StrictInt, portal_id : StrictInt, active_only : Optional[StrictBool] = None, origin : Optional[StrictStr] = None, referer : Optional[StrictStr] = None, portal_id2 : Optional[StrictInt] = None, **kwargs) -> WrappedResponseInt:  # noqa: E501
        """Count members who have access to this package  # noqa: E501

        Query: portal_id, active_only?. Total matching members (for pagination).  # noqa: E501

        :param access_package_id: (required)
        :type access_package_id: int
        :param portal_id: (required)
        :type portal_id: int
        :param active_only:
        :type active_only: bool
        :param origin:
        :type origin: str
        :param referer:
        :type referer: str
        :param portal_id2:
        :type portal_id2: 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: WrappedResponseInt
        """
        kwargs['_return_http_data_only'] = True
        if '_preload_content' in kwargs:
            message = "Error! Please call the count_members_v1_packages_access_package_id_members_count_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.count_members_v1_packages_access_package_id_members_count_get_with_http_info(access_package_id, portal_id, active_only, origin, referer, portal_id2, **kwargs)  # noqa: E501

    @validate_arguments
    async def count_members_v1_packages_access_package_id_members_count_get_with_http_info(self, access_package_id : StrictInt, portal_id : StrictInt, active_only : Optional[StrictBool] = None, origin : Optional[StrictStr] = None, referer : Optional[StrictStr] = None, portal_id2 : Optional[StrictInt] = None, **kwargs) -> ApiResponse:  # noqa: E501
        """Count members who have access to this package  # noqa: E501

        Query: portal_id, active_only?. Total matching members (for pagination).  # noqa: E501

        :param access_package_id: (required)
        :type access_package_id: int
        :param portal_id: (required)
        :type portal_id: int
        :param active_only:
        :type active_only: bool
        :param origin:
        :type origin: str
        :param referer:
        :type referer: str
        :param portal_id2:
        :type portal_id2: 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(WrappedResponseInt, status_code(int), headers(HTTPHeaderDict))
        """

        _params = locals()

        _all_params = [
            'access_package_id',
            'portal_id',
            'active_only',
            'origin',
            'referer',
            'portal_id2'
        ]
        _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 count_members_v1_packages_access_package_id_members_count_get" % _key
                )
            _params[_key] = _val
        del _params['kwargs']

        _collection_formats = {}

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


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

        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', {}))
        if _params['origin'] is not None:
            _header_params['origin'] = _params['origin']

        if _params['referer'] is not None:
            _header_params['referer'] = _params['referer']

        if _params['portal_id2'] is not None:
            _header_params['portal_id'] = _params['portal_id2']

        # 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': "WrappedResponseInt",
            '422': "HTTPValidationError",
        }

        return await self.api_client.call_api(
            '/v1/packages/{access_package_id}/members/count', '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 count_packages_v1_packages_count_get(self, portal_id : StrictInt, is_active : Optional[StrictBool] = None, origin : Optional[StrictStr] = None, referer : Optional[StrictStr] = None, portal_id2 : Optional[StrictInt] = None, **kwargs) -> WrappedResponseInt:  # noqa: E501
        """Count a portal's access packages  # noqa: E501

        Query: portal_id, is_active?. Total matching packages (for pagination).  # noqa: E501

        :param portal_id: (required)
        :type portal_id: int
        :param is_active:
        :type is_active: bool
        :param origin:
        :type origin: str
        :param referer:
        :type referer: str
        :param portal_id2:
        :type portal_id2: 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: WrappedResponseInt
        """
        kwargs['_return_http_data_only'] = True
        if '_preload_content' in kwargs:
            message = "Error! Please call the count_packages_v1_packages_count_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.count_packages_v1_packages_count_get_with_http_info(portal_id, is_active, origin, referer, portal_id2, **kwargs)  # noqa: E501

    @validate_arguments
    async def count_packages_v1_packages_count_get_with_http_info(self, portal_id : StrictInt, is_active : Optional[StrictBool] = None, origin : Optional[StrictStr] = None, referer : Optional[StrictStr] = None, portal_id2 : Optional[StrictInt] = None, **kwargs) -> ApiResponse:  # noqa: E501
        """Count a portal's access packages  # noqa: E501

        Query: portal_id, is_active?. Total matching packages (for pagination).  # noqa: E501

        :param portal_id: (required)
        :type portal_id: int
        :param is_active:
        :type is_active: bool
        :param origin:
        :type origin: str
        :param referer:
        :type referer: str
        :param portal_id2:
        :type portal_id2: 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(WrappedResponseInt, status_code(int), headers(HTTPHeaderDict))
        """

        _params = locals()

        _all_params = [
            'portal_id',
            'is_active',
            'origin',
            'referer',
            'portal_id2'
        ]
        _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 count_packages_v1_packages_count_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('portal_id') is not None:  # noqa: E501
            _query_params.append(('portal_id', _params['portal_id']))

        if _params.get('is_active') is not None:  # noqa: E501
            _query_params.append(('is_active', _params['is_active']))

        # process the header parameters
        _header_params = dict(_params.get('_headers', {}))
        if _params['origin'] is not None:
            _header_params['origin'] = _params['origin']

        if _params['referer'] is not None:
            _header_params['referer'] = _params['referer']

        if _params['portal_id2'] is not None:
            _header_params['portal_id'] = _params['portal_id2']

        # 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': "WrappedResponseInt",
            '422': "HTTPValidationError",
        }

        return await self.api_client.call_api(
            '/v1/packages/count', '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 create_package_v1_packages_post(self, package_in : PackageIn, origin : Optional[StrictStr] = None, referer : Optional[StrictStr] = None, portal_id : Optional[StrictInt] = None, **kwargs) -> WrappedResponseIdOut:  # noqa: E501
        """Create an access package  # noqa: E501


        :param package_in: (required)
        :type package_in: PackageIn
        :param origin:
        :type origin: str
        :param referer:
        :type referer: str
        :param portal_id:
        :type portal_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 create_package_v1_packages_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_package_v1_packages_post_with_http_info(package_in, origin, referer, portal_id, **kwargs)  # noqa: E501

    @validate_arguments
    async def create_package_v1_packages_post_with_http_info(self, package_in : PackageIn, origin : Optional[StrictStr] = None, referer : Optional[StrictStr] = None, portal_id : Optional[StrictInt] = None, **kwargs) -> ApiResponse:  # noqa: E501
        """Create an access package  # noqa: E501


        :param package_in: (required)
        :type package_in: PackageIn
        :param origin:
        :type origin: str
        :param referer:
        :type referer: str
        :param portal_id:
        :type portal_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 = [
            'package_in',
            'origin',
            'referer',
            'portal_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 create_package_v1_packages_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', {}))
        if _params['origin'] is not None:
            _header_params['origin'] = _params['origin']

        if _params['referer'] is not None:
            _header_params['referer'] = _params['referer']

        if _params['portal_id'] is not None:
            _header_params['portal_id'] = _params['portal_id']

        # process the form parameters
        _form_params = []
        _files = {}
        # process the body parameter
        _body_params = None
        if _params['package_in'] is not None:
            _body_params = _params['package_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/packages', '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_package_v1_packages_access_package_id_delete(self, access_package_id : StrictInt, force : Optional[StrictBool] = None, origin : Optional[StrictStr] = None, referer : Optional[StrictStr] = None, portal_id : Optional[StrictInt] = None, **kwargs) -> WrappedResponseIdOut:  # noqa: E501
        """Delete an access package  # noqa: E501

        Free deletion only when nobody holds it; with grants returns 409 unless force=true (then all holders lose access, as if they had never bought it). Prefer PATCH is_active=false to retire.  # noqa: E501

        :param access_package_id: (required)
        :type access_package_id: int
        :param force:
        :type force: bool
        :param origin:
        :type origin: str
        :param referer:
        :type referer: str
        :param portal_id:
        :type portal_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_package_v1_packages_access_package_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_package_v1_packages_access_package_id_delete_with_http_info(access_package_id, force, origin, referer, portal_id, **kwargs)  # noqa: E501

    @validate_arguments
    async def delete_package_v1_packages_access_package_id_delete_with_http_info(self, access_package_id : StrictInt, force : Optional[StrictBool] = None, origin : Optional[StrictStr] = None, referer : Optional[StrictStr] = None, portal_id : Optional[StrictInt] = None, **kwargs) -> ApiResponse:  # noqa: E501
        """Delete an access package  # noqa: E501

        Free deletion only when nobody holds it; with grants returns 409 unless force=true (then all holders lose access, as if they had never bought it). Prefer PATCH is_active=false to retire.  # noqa: E501

        :param access_package_id: (required)
        :type access_package_id: int
        :param force:
        :type force: bool
        :param origin:
        :type origin: str
        :param referer:
        :type referer: str
        :param portal_id:
        :type portal_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 = [
            'access_package_id',
            'force',
            'origin',
            'referer',
            'portal_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_package_v1_packages_access_package_id_delete" % _key
                )
            _params[_key] = _val
        del _params['kwargs']

        _collection_formats = {}

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


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

        # process the header parameters
        _header_params = dict(_params.get('_headers', {}))
        if _params['origin'] is not None:
            _header_params['origin'] = _params['origin']

        if _params['referer'] is not None:
            _header_params['referer'] = _params['referer']

        if _params['portal_id'] is not None:
            _header_params['portal_id'] = _params['portal_id']

        # 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/packages/{access_package_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 delete_rule_v1_packages_access_package_id_rules_rule_id_delete(self, access_package_id : StrictInt, rule_id : StrictInt, origin : Optional[StrictStr] = None, referer : Optional[StrictStr] = None, portal_id : Optional[StrictInt] = None, **kwargs) -> WrappedResponseIdOut:  # noqa: E501
        """Remove an access rule from a package  # noqa: E501

        Revokes the resource for all holders on their next read.  # noqa: E501

        :param access_package_id: (required)
        :type access_package_id: int
        :param rule_id: (required)
        :type rule_id: int
        :param origin:
        :type origin: str
        :param referer:
        :type referer: str
        :param portal_id:
        :type portal_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_rule_v1_packages_access_package_id_rules_rule_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_rule_v1_packages_access_package_id_rules_rule_id_delete_with_http_info(access_package_id, rule_id, origin, referer, portal_id, **kwargs)  # noqa: E501

    @validate_arguments
    async def delete_rule_v1_packages_access_package_id_rules_rule_id_delete_with_http_info(self, access_package_id : StrictInt, rule_id : StrictInt, origin : Optional[StrictStr] = None, referer : Optional[StrictStr] = None, portal_id : Optional[StrictInt] = None, **kwargs) -> ApiResponse:  # noqa: E501
        """Remove an access rule from a package  # noqa: E501

        Revokes the resource for all holders on their next read.  # noqa: E501

        :param access_package_id: (required)
        :type access_package_id: int
        :param rule_id: (required)
        :type rule_id: int
        :param origin:
        :type origin: str
        :param referer:
        :type referer: str
        :param portal_id:
        :type portal_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 = [
            'access_package_id',
            'rule_id',
            'origin',
            'referer',
            'portal_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_rule_v1_packages_access_package_id_rules_rule_id_delete" % _key
                )
            _params[_key] = _val
        del _params['kwargs']

        _collection_formats = {}

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

        if _params['rule_id'] is not None:
            _path_params['rule_id'] = _params['rule_id']


        # process the query parameters
        _query_params = []
        # process the header parameters
        _header_params = dict(_params.get('_headers', {}))
        if _params['origin'] is not None:
            _header_params['origin'] = _params['origin']

        if _params['referer'] is not None:
            _header_params['referer'] = _params['referer']

        if _params['portal_id'] is not None:
            _header_params['portal_id'] = _params['portal_id']

        # 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/packages/{access_package_id}/rules/{rule_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_package_by_slug_v1_packages_by_slug_slug_get(self, slug : StrictStr, **kwargs) -> WrappedResponsePublicPackageOut:  # noqa: E501
        """Get public package data by its direct-link slug (unauthenticated)  # noqa: E501


        :param slug: (required)
        :type slug: str
        :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: WrappedResponsePublicPackageOut
        """
        kwargs['_return_http_data_only'] = True
        if '_preload_content' in kwargs:
            message = "Error! Please call the get_package_by_slug_v1_packages_by_slug_slug_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_package_by_slug_v1_packages_by_slug_slug_get_with_http_info(slug, **kwargs)  # noqa: E501

    @validate_arguments
    async def get_package_by_slug_v1_packages_by_slug_slug_get_with_http_info(self, slug : StrictStr, **kwargs) -> ApiResponse:  # noqa: E501
        """Get public package data by its direct-link slug (unauthenticated)  # noqa: E501


        :param slug: (required)
        :type slug: str
        :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(WrappedResponsePublicPackageOut, status_code(int), headers(HTTPHeaderDict))
        """

        _params = locals()

        _all_params = [
            'slug'
        ]
        _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_package_by_slug_v1_packages_by_slug_slug_get" % _key
                )
            _params[_key] = _val
        del _params['kwargs']

        _collection_formats = {}

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


        # 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 = []  # noqa: E501

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

        return await self.api_client.call_api(
            '/v1/packages/by-slug/{slug}', '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 get_package_v1_packages_access_package_id_get(self, access_package_id : StrictInt, origin : Optional[StrictStr] = None, referer : Optional[StrictStr] = None, portal_id : Optional[StrictInt] = None, **kwargs) -> WrappedResponsePackageDetailOut:  # noqa: E501
        """Get a single access package (with its rules)  # noqa: E501


        :param access_package_id: (required)
        :type access_package_id: int
        :param origin:
        :type origin: str
        :param referer:
        :type referer: str
        :param portal_id:
        :type portal_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: WrappedResponsePackageDetailOut
        """
        kwargs['_return_http_data_only'] = True
        if '_preload_content' in kwargs:
            message = "Error! Please call the get_package_v1_packages_access_package_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_package_v1_packages_access_package_id_get_with_http_info(access_package_id, origin, referer, portal_id, **kwargs)  # noqa: E501

    @validate_arguments
    async def get_package_v1_packages_access_package_id_get_with_http_info(self, access_package_id : StrictInt, origin : Optional[StrictStr] = None, referer : Optional[StrictStr] = None, portal_id : Optional[StrictInt] = None, **kwargs) -> ApiResponse:  # noqa: E501
        """Get a single access package (with its rules)  # noqa: E501


        :param access_package_id: (required)
        :type access_package_id: int
        :param origin:
        :type origin: str
        :param referer:
        :type referer: str
        :param portal_id:
        :type portal_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(WrappedResponsePackageDetailOut, status_code(int), headers(HTTPHeaderDict))
        """

        _params = locals()

        _all_params = [
            'access_package_id',
            'origin',
            'referer',
            'portal_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_package_v1_packages_access_package_id_get" % _key
                )
            _params[_key] = _val
        del _params['kwargs']

        _collection_formats = {}

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


        # process the query parameters
        _query_params = []
        # process the header parameters
        _header_params = dict(_params.get('_headers', {}))
        if _params['origin'] is not None:
            _header_params['origin'] = _params['origin']

        if _params['referer'] is not None:
            _header_params['referer'] = _params['referer']

        if _params['portal_id'] is not None:
            _header_params['portal_id'] = _params['portal_id']

        # 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': "WrappedResponsePackageDetailOut",
            '422': "HTTPValidationError",
        }

        return await self.api_client.call_api(
            '/v1/packages/{access_package_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 get_rules_v1_packages_access_package_id_rules_get(self, access_package_id : StrictInt, origin : Optional[StrictStr] = None, referer : Optional[StrictStr] = None, portal_id : Optional[StrictInt] = None, **kwargs) -> WrappedResponseListRuleOut:  # noqa: E501
        """List a package's access rules  # noqa: E501

        The rules currently set on the package (for displaying the selected state).  # noqa: E501

        :param access_package_id: (required)
        :type access_package_id: int
        :param origin:
        :type origin: str
        :param referer:
        :type referer: str
        :param portal_id:
        :type portal_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: WrappedResponseListRuleOut
        """
        kwargs['_return_http_data_only'] = True
        if '_preload_content' in kwargs:
            message = "Error! Please call the get_rules_v1_packages_access_package_id_rules_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_rules_v1_packages_access_package_id_rules_get_with_http_info(access_package_id, origin, referer, portal_id, **kwargs)  # noqa: E501

    @validate_arguments
    async def get_rules_v1_packages_access_package_id_rules_get_with_http_info(self, access_package_id : StrictInt, origin : Optional[StrictStr] = None, referer : Optional[StrictStr] = None, portal_id : Optional[StrictInt] = None, **kwargs) -> ApiResponse:  # noqa: E501
        """List a package's access rules  # noqa: E501

        The rules currently set on the package (for displaying the selected state).  # noqa: E501

        :param access_package_id: (required)
        :type access_package_id: int
        :param origin:
        :type origin: str
        :param referer:
        :type referer: str
        :param portal_id:
        :type portal_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(WrappedResponseListRuleOut, status_code(int), headers(HTTPHeaderDict))
        """

        _params = locals()

        _all_params = [
            'access_package_id',
            'origin',
            'referer',
            'portal_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_rules_v1_packages_access_package_id_rules_get" % _key
                )
            _params[_key] = _val
        del _params['kwargs']

        _collection_formats = {}

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


        # process the query parameters
        _query_params = []
        # process the header parameters
        _header_params = dict(_params.get('_headers', {}))
        if _params['origin'] is not None:
            _header_params['origin'] = _params['origin']

        if _params['referer'] is not None:
            _header_params['referer'] = _params['referer']

        if _params['portal_id'] is not None:
            _header_params['portal_id'] = _params['portal_id']

        # 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': "WrappedResponseListRuleOut",
            '422': "HTTPValidationError",
        }

        return await self.api_client.call_api(
            '/v1/packages/{access_package_id}/rules', '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 link_product_v1_packages_access_package_id_products_put(self, access_package_id : StrictInt, product_link_in : ProductLinkIn, origin : Optional[StrictStr] = None, referer : Optional[StrictStr] = None, portal_id : Optional[StrictInt] = None, **kwargs) -> WrappedResponseIdOut:  # noqa: E501
        """Link a marketplace product to a package  # noqa: E501


        :param access_package_id: (required)
        :type access_package_id: int
        :param product_link_in: (required)
        :type product_link_in: ProductLinkIn
        :param origin:
        :type origin: str
        :param referer:
        :type referer: str
        :param portal_id:
        :type portal_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 link_product_v1_packages_access_package_id_products_put_with_http_info method with `_preload_content` instead and obtain raw data from ApiResponse.raw_data"  # noqa: E501
            raise ValueError(message)
        return await self.link_product_v1_packages_access_package_id_products_put_with_http_info(access_package_id, product_link_in, origin, referer, portal_id, **kwargs)  # noqa: E501

    @validate_arguments
    async def link_product_v1_packages_access_package_id_products_put_with_http_info(self, access_package_id : StrictInt, product_link_in : ProductLinkIn, origin : Optional[StrictStr] = None, referer : Optional[StrictStr] = None, portal_id : Optional[StrictInt] = None, **kwargs) -> ApiResponse:  # noqa: E501
        """Link a marketplace product to a package  # noqa: E501


        :param access_package_id: (required)
        :type access_package_id: int
        :param product_link_in: (required)
        :type product_link_in: ProductLinkIn
        :param origin:
        :type origin: str
        :param referer:
        :type referer: str
        :param portal_id:
        :type portal_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 = [
            'access_package_id',
            'product_link_in',
            'origin',
            'referer',
            'portal_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 link_product_v1_packages_access_package_id_products_put" % _key
                )
            _params[_key] = _val
        del _params['kwargs']

        _collection_formats = {}

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


        # process the query parameters
        _query_params = []
        # process the header parameters
        _header_params = dict(_params.get('_headers', {}))
        if _params['origin'] is not None:
            _header_params['origin'] = _params['origin']

        if _params['referer'] is not None:
            _header_params['referer'] = _params['referer']

        if _params['portal_id'] is not None:
            _header_params['portal_id'] = _params['portal_id']

        # process the form parameters
        _form_params = []
        _files = {}
        # process the body parameter
        _body_params = None
        if _params['product_link_in'] is not None:
            _body_params = _params['product_link_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/packages/{access_package_id}/products', 'PUT',
            _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_members_v1_packages_access_package_id_members_get(self, access_package_id : StrictInt, portal_id : StrictInt, active_only : Optional[StrictBool] = None, limit : Optional[conint(strict=True, le=200, ge=1)] = None, offset : Optional[conint(strict=True, ge=0)] = None, origin : Optional[StrictStr] = None, referer : Optional[StrictStr] = None, portal_id2 : Optional[StrictInt] = None, **kwargs) -> WrappedResponseListMemberOwnershipOut:  # noqa: E501
        """List members who have access to this package (paginated)  # noqa: E501

        Query: portal_id, active_only?, limit, offset. Use /members/count for the total.  # noqa: E501

        :param access_package_id: (required)
        :type access_package_id: int
        :param portal_id: (required)
        :type portal_id: int
        :param active_only:
        :type active_only: bool
        :param limit:
        :type limit: int
        :param offset:
        :type offset: int
        :param origin:
        :type origin: str
        :param referer:
        :type referer: str
        :param portal_id2:
        :type portal_id2: 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: WrappedResponseListMemberOwnershipOut
        """
        kwargs['_return_http_data_only'] = True
        if '_preload_content' in kwargs:
            message = "Error! Please call the list_members_v1_packages_access_package_id_members_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_members_v1_packages_access_package_id_members_get_with_http_info(access_package_id, portal_id, active_only, limit, offset, origin, referer, portal_id2, **kwargs)  # noqa: E501

    @validate_arguments
    async def list_members_v1_packages_access_package_id_members_get_with_http_info(self, access_package_id : StrictInt, portal_id : StrictInt, active_only : Optional[StrictBool] = None, limit : Optional[conint(strict=True, le=200, ge=1)] = None, offset : Optional[conint(strict=True, ge=0)] = None, origin : Optional[StrictStr] = None, referer : Optional[StrictStr] = None, portal_id2 : Optional[StrictInt] = None, **kwargs) -> ApiResponse:  # noqa: E501
        """List members who have access to this package (paginated)  # noqa: E501

        Query: portal_id, active_only?, limit, offset. Use /members/count for the total.  # noqa: E501

        :param access_package_id: (required)
        :type access_package_id: int
        :param portal_id: (required)
        :type portal_id: int
        :param active_only:
        :type active_only: bool
        :param limit:
        :type limit: int
        :param offset:
        :type offset: int
        :param origin:
        :type origin: str
        :param referer:
        :type referer: str
        :param portal_id2:
        :type portal_id2: 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(WrappedResponseListMemberOwnershipOut, status_code(int), headers(HTTPHeaderDict))
        """

        _params = locals()

        _all_params = [
            'access_package_id',
            'portal_id',
            'active_only',
            'limit',
            'offset',
            'origin',
            'referer',
            'portal_id2'
        ]
        _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_members_v1_packages_access_package_id_members_get" % _key
                )
            _params[_key] = _val
        del _params['kwargs']

        _collection_formats = {}

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


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

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

        if _params.get('limit') is not None:  # noqa: E501
            _query_params.append(('limit', _params['limit']))

        if _params.get('offset') is not None:  # noqa: E501
            _query_params.append(('offset', _params['offset']))

        # process the header parameters
        _header_params = dict(_params.get('_headers', {}))
        if _params['origin'] is not None:
            _header_params['origin'] = _params['origin']

        if _params['referer'] is not None:
            _header_params['referer'] = _params['referer']

        if _params['portal_id2'] is not None:
            _header_params['portal_id'] = _params['portal_id2']

        # 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': "WrappedResponseListMemberOwnershipOut",
            '422': "HTTPValidationError",
        }

        return await self.api_client.call_api(
            '/v1/packages/{access_package_id}/members', '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_packages_v1_packages_get(self, portal_id : StrictInt, is_active : Optional[StrictBool] = None, limit : Optional[conint(strict=True, le=200, ge=1)] = None, offset : Optional[conint(strict=True, ge=0)] = None, origin : Optional[StrictStr] = None, referer : Optional[StrictStr] = None, portal_id2 : Optional[StrictInt] = None, **kwargs) -> WrappedResponseListPackageOut:  # noqa: E501
        """List a portal's access packages (paginated)  # noqa: E501

        Query: portal_id, is_active?, limit, offset. Use /count for the total.  # noqa: E501

        :param portal_id: (required)
        :type portal_id: int
        :param is_active:
        :type is_active: bool
        :param limit:
        :type limit: int
        :param offset:
        :type offset: int
        :param origin:
        :type origin: str
        :param referer:
        :type referer: str
        :param portal_id2:
        :type portal_id2: 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: WrappedResponseListPackageOut
        """
        kwargs['_return_http_data_only'] = True
        if '_preload_content' in kwargs:
            message = "Error! Please call the list_packages_v1_packages_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_packages_v1_packages_get_with_http_info(portal_id, is_active, limit, offset, origin, referer, portal_id2, **kwargs)  # noqa: E501

    @validate_arguments
    async def list_packages_v1_packages_get_with_http_info(self, portal_id : StrictInt, is_active : Optional[StrictBool] = None, limit : Optional[conint(strict=True, le=200, ge=1)] = None, offset : Optional[conint(strict=True, ge=0)] = None, origin : Optional[StrictStr] = None, referer : Optional[StrictStr] = None, portal_id2 : Optional[StrictInt] = None, **kwargs) -> ApiResponse:  # noqa: E501
        """List a portal's access packages (paginated)  # noqa: E501

        Query: portal_id, is_active?, limit, offset. Use /count for the total.  # noqa: E501

        :param portal_id: (required)
        :type portal_id: int
        :param is_active:
        :type is_active: bool
        :param limit:
        :type limit: int
        :param offset:
        :type offset: int
        :param origin:
        :type origin: str
        :param referer:
        :type referer: str
        :param portal_id2:
        :type portal_id2: 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(WrappedResponseListPackageOut, status_code(int), headers(HTTPHeaderDict))
        """

        _params = locals()

        _all_params = [
            'portal_id',
            'is_active',
            'limit',
            'offset',
            'origin',
            'referer',
            'portal_id2'
        ]
        _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_packages_v1_packages_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('portal_id') is not None:  # noqa: E501
            _query_params.append(('portal_id', _params['portal_id']))

        if _params.get('is_active') is not None:  # noqa: E501
            _query_params.append(('is_active', _params['is_active']))

        if _params.get('limit') is not None:  # noqa: E501
            _query_params.append(('limit', _params['limit']))

        if _params.get('offset') is not None:  # noqa: E501
            _query_params.append(('offset', _params['offset']))

        # process the header parameters
        _header_params = dict(_params.get('_headers', {}))
        if _params['origin'] is not None:
            _header_params['origin'] = _params['origin']

        if _params['referer'] is not None:
            _header_params['referer'] = _params['referer']

        if _params['portal_id2'] is not None:
            _header_params['portal_id'] = _params['portal_id2']

        # 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': "WrappedResponseListPackageOut",
            '422': "HTTPValidationError",
        }

        return await self.api_client.call_api(
            '/v1/packages', '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_product_links_v1_packages_access_package_id_products_get(self, access_package_id : StrictInt, origin : Optional[StrictStr] = None, referer : Optional[StrictStr] = None, portal_id : Optional[StrictInt] = None, **kwargs) -> WrappedResponseListProductLinkOut:  # noqa: E501
        """List the marketplace products linked to a package  # noqa: E501


        :param access_package_id: (required)
        :type access_package_id: int
        :param origin:
        :type origin: str
        :param referer:
        :type referer: str
        :param portal_id:
        :type portal_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: WrappedResponseListProductLinkOut
        """
        kwargs['_return_http_data_only'] = True
        if '_preload_content' in kwargs:
            message = "Error! Please call the list_product_links_v1_packages_access_package_id_products_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_product_links_v1_packages_access_package_id_products_get_with_http_info(access_package_id, origin, referer, portal_id, **kwargs)  # noqa: E501

    @validate_arguments
    async def list_product_links_v1_packages_access_package_id_products_get_with_http_info(self, access_package_id : StrictInt, origin : Optional[StrictStr] = None, referer : Optional[StrictStr] = None, portal_id : Optional[StrictInt] = None, **kwargs) -> ApiResponse:  # noqa: E501
        """List the marketplace products linked to a package  # noqa: E501


        :param access_package_id: (required)
        :type access_package_id: int
        :param origin:
        :type origin: str
        :param referer:
        :type referer: str
        :param portal_id:
        :type portal_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(WrappedResponseListProductLinkOut, status_code(int), headers(HTTPHeaderDict))
        """

        _params = locals()

        _all_params = [
            'access_package_id',
            'origin',
            'referer',
            'portal_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 list_product_links_v1_packages_access_package_id_products_get" % _key
                )
            _params[_key] = _val
        del _params['kwargs']

        _collection_formats = {}

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


        # process the query parameters
        _query_params = []
        # process the header parameters
        _header_params = dict(_params.get('_headers', {}))
        if _params['origin'] is not None:
            _header_params['origin'] = _params['origin']

        if _params['referer'] is not None:
            _header_params['referer'] = _params['referer']

        if _params['portal_id'] is not None:
            _header_params['portal_id'] = _params['portal_id']

        # 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': "WrappedResponseListProductLinkOut",
            '422': "HTTPValidationError",
        }

        return await self.api_client.call_api(
            '/v1/packages/{access_package_id}/products', '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 patch_package_v1_packages_access_package_id_patch(self, access_package_id : StrictInt, package_patch_in : PackagePatchIn, origin : Optional[StrictStr] = None, referer : Optional[StrictStr] = None, portal_id : Optional[StrictInt] = None, **kwargs) -> WrappedResponseIdOut:  # noqa: E501
        """Toggle is_active / is_locked  # noqa: E501

        Toggle is_active (gates new grants) / is_locked (hard lock, cuts existing access).  # noqa: E501

        :param access_package_id: (required)
        :type access_package_id: int
        :param package_patch_in: (required)
        :type package_patch_in: PackagePatchIn
        :param origin:
        :type origin: str
        :param referer:
        :type referer: str
        :param portal_id:
        :type portal_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 patch_package_v1_packages_access_package_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.patch_package_v1_packages_access_package_id_patch_with_http_info(access_package_id, package_patch_in, origin, referer, portal_id, **kwargs)  # noqa: E501

    @validate_arguments
    async def patch_package_v1_packages_access_package_id_patch_with_http_info(self, access_package_id : StrictInt, package_patch_in : PackagePatchIn, origin : Optional[StrictStr] = None, referer : Optional[StrictStr] = None, portal_id : Optional[StrictInt] = None, **kwargs) -> ApiResponse:  # noqa: E501
        """Toggle is_active / is_locked  # noqa: E501

        Toggle is_active (gates new grants) / is_locked (hard lock, cuts existing access).  # noqa: E501

        :param access_package_id: (required)
        :type access_package_id: int
        :param package_patch_in: (required)
        :type package_patch_in: PackagePatchIn
        :param origin:
        :type origin: str
        :param referer:
        :type referer: str
        :param portal_id:
        :type portal_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 = [
            'access_package_id',
            'package_patch_in',
            'origin',
            'referer',
            'portal_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 patch_package_v1_packages_access_package_id_patch" % _key
                )
            _params[_key] = _val
        del _params['kwargs']

        _collection_formats = {}

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


        # process the query parameters
        _query_params = []
        # process the header parameters
        _header_params = dict(_params.get('_headers', {}))
        if _params['origin'] is not None:
            _header_params['origin'] = _params['origin']

        if _params['referer'] is not None:
            _header_params['referer'] = _params['referer']

        if _params['portal_id'] is not None:
            _header_params['portal_id'] = _params['portal_id']

        # process the form parameters
        _form_params = []
        _files = {}
        # process the body parameter
        _body_params = None
        if _params['package_patch_in'] is not None:
            _body_params = _params['package_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/packages/{access_package_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'))

    @validate_arguments
    async def set_rule_v1_packages_access_package_id_rules_put(self, access_package_id : StrictInt, package_rule_in : PackageRuleIn, origin : Optional[StrictStr] = None, referer : Optional[StrictStr] = None, portal_id : Optional[StrictInt] = None, **kwargs) -> WrappedResponseIdOut:  # noqa: E501
        """Set an access rule on a package  # noqa: E501


        :param access_package_id: (required)
        :type access_package_id: int
        :param package_rule_in: (required)
        :type package_rule_in: PackageRuleIn
        :param origin:
        :type origin: str
        :param referer:
        :type referer: str
        :param portal_id:
        :type portal_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 set_rule_v1_packages_access_package_id_rules_put_with_http_info method with `_preload_content` instead and obtain raw data from ApiResponse.raw_data"  # noqa: E501
            raise ValueError(message)
        return await self.set_rule_v1_packages_access_package_id_rules_put_with_http_info(access_package_id, package_rule_in, origin, referer, portal_id, **kwargs)  # noqa: E501

    @validate_arguments
    async def set_rule_v1_packages_access_package_id_rules_put_with_http_info(self, access_package_id : StrictInt, package_rule_in : PackageRuleIn, origin : Optional[StrictStr] = None, referer : Optional[StrictStr] = None, portal_id : Optional[StrictInt] = None, **kwargs) -> ApiResponse:  # noqa: E501
        """Set an access rule on a package  # noqa: E501


        :param access_package_id: (required)
        :type access_package_id: int
        :param package_rule_in: (required)
        :type package_rule_in: PackageRuleIn
        :param origin:
        :type origin: str
        :param referer:
        :type referer: str
        :param portal_id:
        :type portal_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 = [
            'access_package_id',
            'package_rule_in',
            'origin',
            'referer',
            'portal_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 set_rule_v1_packages_access_package_id_rules_put" % _key
                )
            _params[_key] = _val
        del _params['kwargs']

        _collection_formats = {}

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


        # process the query parameters
        _query_params = []
        # process the header parameters
        _header_params = dict(_params.get('_headers', {}))
        if _params['origin'] is not None:
            _header_params['origin'] = _params['origin']

        if _params['referer'] is not None:
            _header_params['referer'] = _params['referer']

        if _params['portal_id'] is not None:
            _header_params['portal_id'] = _params['portal_id']

        # process the form parameters
        _form_params = []
        _files = {}
        # process the body parameter
        _body_params = None
        if _params['package_rule_in'] is not None:
            _body_params = _params['package_rule_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/packages/{access_package_id}/rules', 'PUT',
            _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 unlink_product_v1_packages_access_package_id_products_link_id_delete(self, access_package_id : StrictInt, link_id : StrictInt, origin : Optional[StrictStr] = None, referer : Optional[StrictStr] = None, portal_id : Optional[StrictInt] = None, **kwargs) -> WrappedResponseIdOut:  # noqa: E501
        """Unlink a marketplace product from a package  # noqa: E501

        New purchases of the product stop granting this package (existing grants stay).  # noqa: E501

        :param access_package_id: (required)
        :type access_package_id: int
        :param link_id: (required)
        :type link_id: int
        :param origin:
        :type origin: str
        :param referer:
        :type referer: str
        :param portal_id:
        :type portal_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 unlink_product_v1_packages_access_package_id_products_link_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.unlink_product_v1_packages_access_package_id_products_link_id_delete_with_http_info(access_package_id, link_id, origin, referer, portal_id, **kwargs)  # noqa: E501

    @validate_arguments
    async def unlink_product_v1_packages_access_package_id_products_link_id_delete_with_http_info(self, access_package_id : StrictInt, link_id : StrictInt, origin : Optional[StrictStr] = None, referer : Optional[StrictStr] = None, portal_id : Optional[StrictInt] = None, **kwargs) -> ApiResponse:  # noqa: E501
        """Unlink a marketplace product from a package  # noqa: E501

        New purchases of the product stop granting this package (existing grants stay).  # noqa: E501

        :param access_package_id: (required)
        :type access_package_id: int
        :param link_id: (required)
        :type link_id: int
        :param origin:
        :type origin: str
        :param referer:
        :type referer: str
        :param portal_id:
        :type portal_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 = [
            'access_package_id',
            'link_id',
            'origin',
            'referer',
            'portal_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 unlink_product_v1_packages_access_package_id_products_link_id_delete" % _key
                )
            _params[_key] = _val
        del _params['kwargs']

        _collection_formats = {}

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

        if _params['link_id'] is not None:
            _path_params['link_id'] = _params['link_id']


        # process the query parameters
        _query_params = []
        # process the header parameters
        _header_params = dict(_params.get('_headers', {}))
        if _params['origin'] is not None:
            _header_params['origin'] = _params['origin']

        if _params['referer'] is not None:
            _header_params['referer'] = _params['referer']

        if _params['portal_id'] is not None:
            _header_params['portal_id'] = _params['portal_id']

        # 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/packages/{access_package_id}/products/{link_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'))
