"""
Autogenerated state module using `pop-create-idem <https://gitlab.com/saltstack/pop/pop-create-idem>`__

hub.exec.boto3.client.apigateway.create_rest_api
hub.exec.boto3.client.apigateway.delete_rest_api
hub.exec.boto3.client.apigateway.get_rest_api
hub.exec.boto3.client.apigateway.import_rest_api
hub.exec.boto3.client.apigateway.put_rest_api
hub.exec.boto3.client.apigateway.update_rest_api
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, description: Text = None, version: Text = None, clone_from: Text = None, binary_media_types: List = None, minimum_compression_size: int = None, api_key_source: Text = None, endpoint_configuration: Dict = None, policy: Text = None, tags: Dict = None, disable_execute_api_endpoint: bool = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a new RestApi resource.

    Args:
        name(Text): [Required] The name of the RestApi.
        description(Text, optional): The description of the RestApi. Defaults to None.
        version(Text, optional): A version identifier for the API. Defaults to None.
        clone_from(Text, optional): The ID of the RestApi that you want to clone from. Defaults to None.
        binary_media_types(List, optional): The list of binary media types supported by the RestApi. By default, the RestApi supports only
            UTF-8-encoded text payloads. Defaults to None.
        minimum_compression_size(int, optional): A nullable integer that is used to enable compression (with non-negative between 0 and 10485760
            (10M) bytes, inclusive) or disable compression (with a null value) on an API. When compression
            is enabled, compression or decompression is not applied on the payload if the payload size is
            smaller than this value. Setting it to zero allows compression for any payload size. Defaults to None.
        api_key_source(Text, optional): The source of the API key for metering requests according to a usage plan. Valid values are:
            HEADER to read the API key from the X-API-Key header of a request. AUTHORIZER to read the API
            key from the UsageIdentifierKey from a custom authorizer. Defaults to None.
        endpoint_configuration(Dict, optional): The endpoint configuration of this RestApi showing the endpoint types of the API. Defaults to None.
        policy(Text, optional): A stringified JSON policy document that applies to this RestApi regardless of the caller and
            Method configuration. Defaults to None.
        tags(Dict, optional): The key-value map of strings. The valid character set is [a-zA-Z+-=._:/]. The tag key can be up
            to 128 characters and must not start with aws:. The tag value can be up to 256 characters. Defaults to None.
        disable_execute_api_endpoint(bool, optional): Specifies whether clients can invoke your API by using the default execute-api endpoint. By
            default, clients can invoke your API with the default https://{api_id}.execute-
            api.{region}.amazonaws.com endpoint. To require that clients use a custom domain name to invoke
            your API, disable the default endpoint. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.apigateway.rest_api.present:
                - name: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.apigateway.rest_api.id(
        ctx,
        jmes_path=name
    )
    if ret["status"]:
        # name is now the first id that matched the JMES search path
        name = ret["ret"]
    

    
    before = await hub.exec.boto3.client.apigateway.get_rest_api(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.apigateway.create_rest_api(
                ctx,
                
                
                **{"Name": name, "description": description, "version": version, "cloneFrom": clone_from, "binaryMediaTypes": binary_media_types, "minimumCompressionSize": minimum_compression_size, "apiKeySource": api_key_source, "endpointConfiguration": endpoint_configuration, "policy": policy, "tags": tags, "disableExecuteApiEndpoint": disable_execute_api_endpoint}
            )
            result["result"] = ret["status"]
            if not result["result"]:
                result["comment"] = ret["comment"]
                return result
            ret["comment"] = f"Created '{name}'"
        except hub.tool.boto3.exception.ClientError as e:
            result["comment"] = f"{e.__class__.__name__}: {e}"

    
    # TODO perform other modifications as needed here
    ...

    after = await hub.exec.boto3.client.apigateway.get_rest_api(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, rest_api_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified API.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        rest_api_id(Text): [Required] The string identifier of the associated RestApi.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.apigateway.rest_api.absent:
                - name: value
                - rest_api_id: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.apigateway.rest_api.id(
        ctx,
        jmes_path=name
    )
    if ret["status"]:
        # name is now the first id that matched the JMES search path
        name = ret["ret"]
    

    

    before = await hub.exec.boto3.client.apigateway.get_rest_api(name)

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.apigateway.delete_rest_api(
                ctx,
                
                
                **{"restApiId": rest_api_id}
            )
            result["result"] = ret["status"]
            if not result["result"]:
                result["comment"] = ret["comment"]
                return result
            result["comment"] = f"Deleted '{name}'"
        except hub.tool.boto3.exception.ClientError as e:
            result["comment"] = f"{e.__class__.__name__}: {e}"

    

    after = await hub.exec.boto3.client.apigateway.get_rest_api(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

