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

hub.exec.boto3.client.appsync.create_api_key
hub.exec.boto3.client.appsync.delete_api_key
hub.exec.boto3.client.appsync.list_api_keys
hub.exec.boto3.client.appsync.update_api_key
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, api_id: Text, description: Text = None, expires: int = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a unique key that you can distribute to clients who are executing your API.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        api_id(Text): The ID for your GraphQL API.
        description(Text, optional): A description of the purpose of the API key. Defaults to None.
        expires(int, optional): The time from creation time after which the API key expires. The date is represented as seconds
            since the epoch, rounded down to the nearest hour. The default value for this parameter is 7
            days from creation time. For more information, see . Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

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

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

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

