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

hub.exec.boto3.client.appstream.create_stack
hub.exec.boto3.client.appstream.delete_stack
hub.exec.boto3.client.appstream.describe_stacks
hub.exec.boto3.client.appstream.update_stack
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, description: Text = None, display_name: Text = None, storage_connectors: List = None, redirect_url: Text = None, feedback_url: Text = None, user_settings: List = None, application_settings: Dict = None, tags: Dict = None, access_endpoints: List = None, embed_host_domains: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a stack to start streaming applications to users. A stack consists of an associated fleet, user access
    policies, and storage configurations.

    Args:
        name(Text): The name of the stack.
        description(Text, optional): The description to display. Defaults to None.
        display_name(Text, optional): The stack name to display. Defaults to None.
        storage_connectors(List, optional): The storage connectors to enable. Defaults to None.
        redirect_url(Text, optional): The URL that users are redirected to after their streaming session ends. Defaults to None.
        feedback_url(Text, optional): The URL that users are redirected to after they click the Send Feedback link. If no URL is
            specified, no Send Feedback link is displayed. Defaults to None.
        user_settings(List, optional): The actions that are enabled or disabled for users during their streaming sessions. By default,
            these actions are enabled. Defaults to None.
        application_settings(Dict, optional): The persistent application settings for users of a stack. When these settings are enabled,
            changes that users make to applications and Windows settings are automatically saved after each
            session and applied to the next session. Defaults to None.
        tags(Dict, optional): The tags to associate with the stack. A tag is a key-value pair, and the value is optional. For
            example, Environment=Test. If you do not specify a value, Environment=.  If you do not specify a
            value, the value is set to an empty string. Generally allowed characters are: letters, numbers,
            and spaces representable in UTF-8, and the following special characters:  _ . : / = + \ - @ For
            more information about tags, see Tagging Your Resources in the Amazon AppStream 2.0
            Administration Guide. Defaults to None.
        access_endpoints(List, optional): The list of interface VPC endpoint (interface endpoint) objects. Users of the stack can connect
            to AppStream 2.0 only through the specified endpoints. Defaults to None.
        embed_host_domains(List, optional): The domains where AppStream 2.0 streaming sessions can be embedded in an iframe. You must
            approve the domains that you want to host embedded AppStream 2.0 streaming sessions. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.appstream.create_stack(
                ctx,
                
                
                **{"Name": name, "Description": description, "DisplayName": display_name, "StorageConnectors": storage_connectors, "RedirectURL": redirect_url, "FeedbackURL": feedback_url, "UserSettings": user_settings, "ApplicationSettings": application_settings, "Tags": tags, "AccessEndpoints": access_endpoints, "EmbedHostDomains": embed_host_domains}
            )
            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.appstream.describe_stacks(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified stack. After the stack is deleted, the application streaming environment provided by the
    stack is no longer available to users. Also, any reservations made for application streaming sessions for the
    stack are released.

    Args:
        name(Text): The name of the stack.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

