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

hub.exec.boto3.client.appstream.create_image_builder
hub.exec.boto3.client.appstream.delete_image_builder
hub.exec.boto3.client.appstream.describe_image_builders
hub.exec.boto3.client.appstream.start_image_builder
hub.exec.boto3.client.appstream.stop_image_builder
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, instance_type: Text, image_name: Text = None, image_arn: Text = None, description: Text = None, display_name: Text = None, vpc_config: Dict = None, iam_role_arn: Text = None, enable_default_internet_access: bool = None, domain_join_info: Dict = None, appstream_agent_version: Text = None, tags: Dict = None, access_endpoints: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates an image builder. An image builder is a virtual machine that is used to create an image. The initial
    state of the builder is PENDING. When it is ready, the state is RUNNING.

    Args:
        name(Text): A unique name for the image builder.
        image_name(Text, optional): The name of the image used to create the image builder. Defaults to None.
        image_arn(Text, optional): The ARN of the public, private, or shared image to use. Defaults to None.
        instance_type(Text): The instance type to use when launching the image builder. The following instance types are
            available:   stream.standard.small   stream.standard.medium   stream.standard.large
            stream.compute.large   stream.compute.xlarge   stream.compute.2xlarge   stream.compute.4xlarge
            stream.compute.8xlarge   stream.memory.large   stream.memory.xlarge   stream.memory.2xlarge
            stream.memory.4xlarge   stream.memory.8xlarge   stream.memory.z1d.large
            stream.memory.z1d.xlarge   stream.memory.z1d.2xlarge   stream.memory.z1d.3xlarge
            stream.memory.z1d.6xlarge   stream.memory.z1d.12xlarge   stream.graphics-design.large
            stream.graphics-design.xlarge   stream.graphics-design.2xlarge   stream.graphics-design.4xlarge
            stream.graphics-desktop.2xlarge   stream.graphics.g4dn.xlarge   stream.graphics.g4dn.2xlarge
            stream.graphics.g4dn.4xlarge   stream.graphics.g4dn.8xlarge   stream.graphics.g4dn.12xlarge
            stream.graphics.g4dn.16xlarge   stream.graphics-pro.4xlarge   stream.graphics-pro.8xlarge
            stream.graphics-pro.16xlarge.
        description(Text, optional): The description to display. Defaults to None.
        display_name(Text, optional): The image builder name to display. Defaults to None.
        vpc_config(Dict, optional): The VPC configuration for the image builder. You can specify only one subnet. Defaults to None.
        iam_role_arn(Text, optional): The Amazon Resource Name (ARN) of the IAM role to apply to the image builder. To assume a role,
            the image builder calls the AWS Security Token Service (STS) AssumeRole API operation and passes
            the ARN of the role to use. The operation creates a new session with temporary credentials.
            AppStream 2.0 retrieves the temporary credentials and creates the appstream_machine_role
            credential profile on the instance. For more information, see Using an IAM Role to Grant
            Permissions to Applications and Scripts Running on AppStream 2.0 Streaming Instances in the
            Amazon AppStream 2.0 Administration Guide. Defaults to None.
        enable_default_internet_access(bool, optional): Enables or disables default internet access for the image builder. Defaults to None.
        domain_join_info(Dict, optional): The name of the directory and organizational unit (OU) to use to join the image builder to a
            Microsoft Active Directory domain. Defaults to None.
        appstream_agent_version(Text, optional): The version of the AppStream 2.0 agent to use for this image builder. To use the latest version
            of the AppStream 2.0 agent, specify [LATEST]. Defaults to None.
        tags(Dict, optional): The tags to associate with the image builder. A tag is a key-value pair, and the value is
            optional. For example, Environment=Test. If you do not specify a value, Environment=.  Generally
            allowed characters are: letters, numbers, and spaces representable in UTF-8, and the following
            special characters:  _ . : / = + \ - @ If you do not specify a value, the value is set to an
            empty string. 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. Administrators can connect to
            the image builder only through the specified endpoints. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.appstream.create_image_builder(
                ctx,
                
                
                **{"Name": name, "ImageName": image_name, "ImageArn": image_arn, "InstanceType": instance_type, "Description": description, "DisplayName": display_name, "VpcConfig": vpc_config, "IamRoleArn": iam_role_arn, "EnableDefaultInternetAccess": enable_default_internet_access, "DomainJoinInfo": domain_join_info, "AppstreamAgentVersion": appstream_agent_version, "Tags": tags, "AccessEndpoints": access_endpoints}
            )
            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_image_builders(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 image builder and releases the capacity.

    Args:
        name(Text): The name of the image builder.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

