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

hub.exec.boto3.client.emr_containers.create_managed_endpoint
hub.exec.boto3.client.emr_containers.delete_managed_endpoint
hub.exec.boto3.client.emr_containers.describe_managed_endpoint
hub.exec.boto3.client.emr_containers.list_managed_endpoints
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, virtual_cluster_id: Text, type_: Text, release_label: Text, execution_role_arn: Text, certificate_arn: Text, client_token: Text, configuration_overrides: Dict = None, tags: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a managed endpoint. A managed endpoint is a gateway that connects EMR Studio to Amazon EMR on EKS so
    that EMR Studio can communicate with your virtual cluster.

    Args:
        name(Text): The name of the managed endpoint.
        virtual_cluster_id(Text): The ID of the virtual cluster for which a managed endpoint is created.
        type_(Text): The type of the managed endpoint.
        release_label(Text): The Amazon EMR release version.
        execution_role_arn(Text): The ARN of the execution role.
        certificate_arn(Text): The certificate ARN of the managed endpoint.
        configuration_overrides(Dict, optional): The configuration settings that will be used to override existing configurations. Defaults to None.
        client_token(Text): The client idempotency token for this create call.
        tags(Dict, optional): The tags of the managed endpoint. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.emr_containers.managed_endpoint.present:
                - name: value
                - virtual_cluster_id: value
                - type_: value
                - release_label: value
                - execution_role_arn: value
                - certificate_arn: value
                - client_token: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.emr_containers.managed_endpoint.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.emr_containers.describe_managed_endpoint(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.emr_containers.create_managed_endpoint(
                ctx,
                
                
                **{"Name": name, "virtualClusterId": virtual_cluster_id, "type": type_, "releaseLabel": release_label, "executionRoleArn": execution_role_arn, "certificateArn": certificate_arn, "configurationOverrides": configuration_overrides, "clientToken": client_token, "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.emr_containers.describe_managed_endpoint(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, id_: Text, virtual_cluster_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a managed endpoint. A managed endpoint is a gateway that connects EMR Studio to Amazon EMR on EKS so
    that EMR Studio can communicate with your virtual cluster.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        id_(Text): The ID of the managed endpoint.
        virtual_cluster_id(Text): The ID of the endpoint's virtual cluster.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

