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

hub.exec.boto3.client.appconfig.create_environment
hub.exec.boto3.client.appconfig.delete_environment
hub.exec.boto3.client.appconfig.get_environment
hub.exec.boto3.client.appconfig.list_environments
hub.exec.boto3.client.appconfig.update_environment
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, application_id: Text, description: Text = None, monitors: List = None, tags: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    For each application, you define one or more environments. An environment is a logical deployment group of
    AppConfig targets, such as applications in a Beta or Production environment. You can also define environments
    for application subcomponents such as the Web, Mobile and Back-end components for your application. You can
    configure Amazon CloudWatch alarms for each environment. The system monitors alarms during a configuration
    deployment. If an alarm is triggered, the system rolls back the configuration.

    Args:
        name(Text): A name for the environment.
        application_id(Text): The application ID.
        description(Text, optional): A description of the environment. Defaults to None.
        monitors(List, optional): Amazon CloudWatch alarms to monitor during the deployment process. Defaults to None.
        tags(Dict, optional): Metadata to assign to the environment. Tags help organize and categorize your AppConfig
            resources. Each tag consists of a key and an optional value, both of which you define. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.appconfig.create_environment(
                ctx,
                
                
                **{"Name": name, "ApplicationId": application_id, "Description": description, "Monitors": monitors, "Tags": tags}
            )
            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.appconfig.get_environment(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, application_id: Text, environment_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Delete an environment. Deleting an environment does not delete a configuration from a host.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        application_id(Text): The application ID that includes the environment you want to delete.
        environment_id(Text): The ID of the environment you want to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.appconfig.environment.absent:
                - name: value
                - application_id: value
                - environment_id: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.appconfig.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.appconfig.get_environment(name)

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

