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

hub.exec.boto3.client.elasticbeanstalk.create_application
hub.exec.boto3.client.elasticbeanstalk.delete_application
hub.exec.boto3.client.elasticbeanstalk.describe_applications
hub.exec.boto3.client.elasticbeanstalk.update_application
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, application_name: Text, description: Text = None, resource_lifecycle_config: Dict = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates an application that has one configuration template named default and no application versions.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        application_name(Text): The name of the application. Must be unique within your account.
        description(Text, optional): Your description of the application. Defaults to None.
        resource_lifecycle_config(Dict, optional): Specifies an application resource lifecycle configuration to prevent your application from
            accumulating too many versions. Defaults to None.
        tags(List, optional): Specifies the tags applied to the application. Elastic Beanstalk applies these tags only to the
            application. Environments that you create in the application don't inherit the tags. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.elasticbeanstalk.create_application(
                ctx,
                
                
                **{"ApplicationName": application_name, "Description": description, "ResourceLifecycleConfig": resource_lifecycle_config, "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.elasticbeanstalk.describe_applications(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, application_name: Text, terminate_env_by_force: bool = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified application along with all associated versions and configurations. The application
    versions will not be deleted from your Amazon S3 bucket.  You cannot delete an application that has a running
    environment.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        application_name(Text): The name of the application to delete.
        terminate_env_by_force(bool, optional): When set to true, running environments will be terminated before deleting the application. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.elasticbeanstalk.application.absent:
                - name: value
                - application_name: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.elasticbeanstalk.application.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.elasticbeanstalk.describe_applications(name)

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.elasticbeanstalk.delete_application(
                ctx,
                
                
                **{"ApplicationName": application_name, "TerminateEnvByForce": terminate_env_by_force}
            )
            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.elasticbeanstalk.describe_applications(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

