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

hub.exec.boto3.client.appsync.create_api_cache
hub.exec.boto3.client.appsync.delete_api_cache
hub.exec.boto3.client.appsync.flush_api_cache
hub.exec.boto3.client.appsync.get_api_cache
hub.exec.boto3.client.appsync.update_api_cache
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, api_id: Text, ttl: int, api_caching_behavior: Text, type_: Text, transit_encryption_enabled: bool = None, at_rest_encryption_enabled: bool = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a cache for the GraphQL API.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        api_id(Text): The GraphQL API Id.
        ttl(int): TTL in seconds for cache entries. Valid values are between 1 and 3600 seconds.
        transit_encryption_enabled(bool, optional): Transit encryption flag when connecting to cache. This setting cannot be updated after creation. Defaults to None.
        at_rest_encryption_enabled(bool, optional): At rest encryption flag for cache. This setting cannot be updated after creation. Defaults to None.
        api_caching_behavior(Text): Caching behavior.    FULL_REQUEST_CACHING: All requests are fully cached.
            PER_RESOLVER_CACHING: Individual resolvers that you specify are cached.
        type_(Text): The cache instance type. Valid values are     SMALL     MEDIUM     LARGE     XLARGE     LARGE_2X
            LARGE_4X     LARGE_8X (not available in all regions)    LARGE_12X    Historically, instance
            types were identified by an EC2-style value. As of July 2020, this is deprecated, and the
            generic identifiers above should be used. The following legacy instance types are available, but
            their use is discouraged:    T2_SMALL: A t2.small instance type.    T2_MEDIUM: A t2.medium
            instance type.    R4_LARGE: A r4.large instance type.    R4_XLARGE: A r4.xlarge instance type.
            R4_2XLARGE: A r4.2xlarge instance type.    R4_4XLARGE: A r4.4xlarge instance type.
            R4_8XLARGE: A r4.8xlarge instance type.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.appsync.api_cache.present:
                - name: value
                - api_id: value
                - ttl: value
                - api_caching_behavior: value
                - type_: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.appsync.api_cache.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.appsync.get_api_cache(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.appsync.create_api_cache(
                ctx,
                
                
                **{"apiId": api_id, "ttl": ttl, "transitEncryptionEnabled": transit_encryption_enabled, "atRestEncryptionEnabled": at_rest_encryption_enabled, "apiCachingBehavior": api_caching_behavior, "type": type_}
            )
            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.appsync.get_api_cache(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, api_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes an ApiCache object.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        api_id(Text): The API ID.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.appsync.api_cache.absent:
                - name: value
                - api_id: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.appsync.api_cache.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.appsync.get_api_cache(name)

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.appsync.delete_api_cache(
                ctx,
                
                
                **{"apiId": 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.appsync.get_api_cache(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

