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

hub.exec.boto3.client.amplify.create_backend_environment
hub.exec.boto3.client.amplify.delete_backend_environment
hub.exec.boto3.client.amplify.get_backend_environment
hub.exec.boto3.client.amplify.list_backend_environments
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, app_id: Text, environment_name: Text, stack_name: Text = None, deployment_artifacts: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
     Creates a new backend environment for an Amplify app.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        app_id(Text):  The unique ID for an Amplify app.
        environment_name(Text):  The name for the backend environment.
        stack_name(Text, optional):  The AWS CloudFormation stack name of a backend environment. Defaults to None.
        deployment_artifacts(Text, optional):  The name of deployment artifacts. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.amplify.backend_environment.present:
                - name: value
                - app_id: value
                - environment_name: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.amplify.backend_environment.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.amplify.get_backend_environment(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.amplify.create_backend_environment(
                ctx,
                
                
                **{"appId": app_id, "environmentName": environment_name, "stackName": stack_name, "deploymentArtifacts": deployment_artifacts}
            )
            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.amplify.get_backend_environment(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, app_id: Text, environment_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
     Deletes a backend environment for an Amplify app.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        app_id(Text):  The unique ID of an Amplify app.
        environment_name(Text):  The name of a backend environment of an Amplify app.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.amplify.backend_environment.absent:
                - name: value
                - app_id: value
                - environment_name: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.amplify.backend_environment.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.amplify.get_backend_environment(name)

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

