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

hub.exec.boto3.client.appsync.create_type
hub.exec.boto3.client.appsync.delete_type
hub.exec.boto3.client.appsync.get_type
hub.exec.boto3.client.appsync.list_types
hub.exec.boto3.client.appsync.update_type
"""



from typing import *
import dict_tools.differ as differ


__virtualname__ = "type"
async def present(hub, ctx, name: Text, api_id: Text, definition: Text, format_: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a Type object.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        api_id(Text): The API ID.
        definition(Text): The type definition, in GraphQL Schema Definition Language (SDL) format. For more information,
            see the GraphQL SDL documentation.
        format_(Text): The type format: SDL or JSON.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

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

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

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

