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

hub.exec.boto3.client.appsync.create_graphql_api
hub.exec.boto3.client.appsync.delete_graphql_api
hub.exec.boto3.client.appsync.get_graphql_api
hub.exec.boto3.client.appsync.update_graphql_api
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, authentication_type: Text, log_config: Dict = None, user_pool_config: Dict = None, open_id_connect_config: Dict = None, tags: Dict = None, additional_authentication_providers: List = None, xray_enabled: bool = None, lambda_authorizer_config: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a GraphqlApi object.

    Args:
        name(Text): A user-supplied name for the GraphqlApi.
        log_config(Dict, optional): The Amazon CloudWatch Logs configuration. Defaults to None.
        authentication_type(Text): The authentication type: API key, Identity and Access Management, OIDC, or Amazon Cognito user
            pools.
        user_pool_config(Dict, optional): The Amazon Cognito user pool configuration. Defaults to None.
        open_id_connect_config(Dict, optional): The OpenID Connect configuration. Defaults to None.
        tags(Dict, optional): A TagMap object. Defaults to None.
        additional_authentication_providers(List, optional): A list of additional authentication providers for the GraphqlApi API. Defaults to None.
        xray_enabled(bool, optional): A flag indicating whether to enable X-Ray tracing for the GraphqlApi. Defaults to None.
        lambda_authorizer_config(Dict, optional): Configuration for AWS Lambda function authorization. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.appsync.create_graphql_api(
                ctx,
                
                
                **{"Name": name, "logConfig": log_config, "authenticationType": authentication_type, "userPoolConfig": user_pool_config, "openIDConnectConfig": open_id_connect_config, "tags": tags, "additionalAuthenticationProviders": additional_authentication_providers, "xrayEnabled": xray_enabled, "lambdaAuthorizerConfig": lambda_authorizer_config}
            )
            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_graphql_api(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 a GraphqlApi 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.graphql_api.absent:
                - name: value
                - api_id: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.appsync.graphql_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.appsync.get_graphql_api(name)

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

