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

hub.exec.boto3.client.sms.create_app
hub.exec.boto3.client.sms.delete_app
hub.exec.boto3.client.sms.get_app
hub.exec.boto3.client.sms.launch_app
hub.exec.boto3.client.sms.list_apps
hub.exec.boto3.client.sms.terminate_app
hub.exec.boto3.client.sms.update_app
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text = None, description: Text = None, role_name: Text = None, client_token: Text = None, server_groups: List = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates an application. An application consists of one or more server groups. Each server group contain one or
    more servers.

    Args:
        name(Text, optional): The name of the new application. Defaults to None.
        description(Text, optional): The description of the new application. Defaults to None.
        role_name(Text, optional): The name of the service role in the customer's account to be used by AWS SMS. Defaults to None.
        client_token(Text, optional): A unique, case-sensitive identifier that you provide to ensure the idempotency of application
            creation. Defaults to None.
        server_groups(List, optional): The server groups to include in the application. Defaults to None.
        tags(List, optional): The tags to be associated with the application. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.sms.create_app(
                ctx,
                
                
                **{"Name": name, "description": description, "roleName": role_name, "clientToken": client_token, "serverGroups": server_groups, "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.sms.get_app(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, app_id: Text = None, force_stop_app_replication: bool = None, force_terminate_app: bool = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified application. Optionally deletes the launched stack associated with the application and all
    AWS SMS replication jobs for servers in the application.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        app_id(Text, optional): The ID of the application. Defaults to None.
        force_stop_app_replication(bool, optional): Indicates whether to stop all replication jobs corresponding to the servers in the application
            while deleting the application. Defaults to None.
        force_terminate_app(bool, optional): Indicates whether to terminate the stack corresponding to the application while deleting the
            application. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.sms.delete_app(
                ctx,
                
                
                **{"appId": app_id, "forceStopAppReplication": force_stop_app_replication, "forceTerminateApp": force_terminate_app}
            )
            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.sms.get_app(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

