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

hub.exec.boto3.client.appmesh.create_virtual_node
hub.exec.boto3.client.appmesh.delete_virtual_node
hub.exec.boto3.client.appmesh.describe_virtual_node
hub.exec.boto3.client.appmesh.list_virtual_nodes
hub.exec.boto3.client.appmesh.update_virtual_node
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, mesh_name: Text, spec: Dict, virtual_node_name: Text, client_token: Text = None, mesh_owner: Text = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a virtual node within a service mesh.  A virtual node acts as a logical pointer to a particular task
    group, such as an Amazon ECS service or a Kubernetes deployment. When you create a virtual node, you can specify
    the service discovery information for your task group, and whether the proxy running in a task group will
    communicate with other proxies using Transport Layer Security (TLS). You define a listener for any inbound
    traffic that your virtual node expects. Any virtual service that your virtual node expects to communicate to is
    specified as a backend. The response metadata for your new virtual node contains the arn that is associated with
    the virtual node. Set this value to the full ARN; for example, arn:aws:appmesh:us-
    west-2:123456789012:myMesh/default/virtualNode/myApp) as the APPMESH_RESOURCE_ARN environment variable for your
    task group's Envoy proxy container in your task definition or pod spec. This is then mapped to the node.id and
    node.cluster Envoy parameters.  By default, App Mesh uses the name of the resource you specified in
    APPMESH_RESOURCE_ARN when Envoy is referring to itself in metrics and traces. You can override this behavior by
    setting the APPMESH_RESOURCE_CLUSTER environment variable with your own name.  For more information about
    virtual nodes, see Virtual nodes. You must be using 1.15.0 or later of the Envoy image when setting these
    variables. For more information aboutApp Mesh Envoy variables, see Envoy image in the AWS App Mesh User Guide.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        client_token(Text, optional): Unique, case-sensitive identifier that you provide to ensure the idempotency of the request. Up
            to 36 letters, numbers, hyphens, and underscores are allowed. Defaults to None.
        mesh_name(Text): The name of the service mesh to create the virtual node in.
        mesh_owner(Text, optional): The AWS IAM account ID of the service mesh owner. If the account ID is not your own, then the
            account that you specify must share the mesh with your account before you can create the
            resource in the service mesh. For more information about mesh sharing, see Working with shared
            meshes. Defaults to None.
        spec(Dict): The virtual node specification to apply.
        tags(List, optional): Optional metadata that you can apply to the virtual node to assist with categorization and
            organization. Each tag consists of a key and an optional value, both of which you define. Tag
            keys can have a maximum character length of 128 characters, and tag values can have a maximum
            length of 256 characters. Defaults to None.
        virtual_node_name(Text): The name to use for the virtual node.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.appmesh.virtual_node.present:
                - name: value
                - mesh_name: value
                - spec: value
                - virtual_node_name: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.appmesh.virtual_node.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.appmesh.describe_virtual_node(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.appmesh.create_virtual_node(
                ctx,
                
                
                **{"clientToken": client_token, "meshName": mesh_name, "meshOwner": mesh_owner, "spec": spec, "tags": tags, "virtualNodeName": virtual_node_name}
            )
            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.appmesh.describe_virtual_node(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, mesh_name: Text, virtual_node_name: Text, mesh_owner: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes an existing virtual node. You must delete any virtual services that list a virtual node as a service
    provider before you can delete the virtual node itself.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        mesh_name(Text): The name of the service mesh to delete the virtual node in.
        mesh_owner(Text, optional): The AWS IAM account ID of the service mesh owner. If the account ID is not your own, then it's
            the ID of the account that shared the mesh with your account. For more information about mesh
            sharing, see Working with shared meshes. Defaults to None.
        virtual_node_name(Text): The name of the virtual node to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.appmesh.delete_virtual_node(
                ctx,
                
                
                **{"meshName": mesh_name, "meshOwner": mesh_owner, "virtualNodeName": virtual_node_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.appmesh.describe_virtual_node(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

