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

hub.exec.boto3.client.managedblockchain.create_node
hub.exec.boto3.client.managedblockchain.delete_node
hub.exec.boto3.client.managedblockchain.get_node
hub.exec.boto3.client.managedblockchain.list_nodes
hub.exec.boto3.client.managedblockchain.update_node
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, client_request_token: Text, network_id: Text, node_configuration: Dict, member_id: Text = None, tags: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a node on the specified blockchain network. Applies to Hyperledger Fabric and Ethereum.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        client_request_token(Text): A unique, case-sensitive identifier that you provide to ensure the idempotency of the operation.
            An idempotent operation completes no more than one time. This identifier is required only if you
            make a service request directly using an HTTP client. It is generated automatically if you use
            an AWS SDK or the AWS CLI.
        network_id(Text): The unique identifier of the network for the node. Ethereum public networks have the following
            NetworkIds:    n-ethereum-mainnet     n-ethereum-rinkeby     n-ethereum-ropsten.
        member_id(Text, optional): The unique identifier of the member that owns this node. Applies only to Hyperledger Fabric. Defaults to None.
        node_configuration(Dict): The properties of a node configuration.
        tags(Dict, optional): Tags to assign to the node. Each tag consists of a key and optional value. When specifying tags
            during creation, you can specify multiple key-value pairs in a single request, with an overall
            maximum of 50 tags added to each resource. For more information about tags, see Tagging
            Resources in the Amazon Managed Blockchain Ethereum Developer Guide, or Tagging Resources in the
            Amazon Managed Blockchain Hyperledger Fabric Developer Guide. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.managedblockchain.node.present:
                - name: value
                - client_request_token: value
                - network_id: value
                - node_configuration: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.managedblockchain.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.managedblockchain.get_node(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.managedblockchain.create_node(
                ctx,
                
                
                **{"ClientRequestToken": client_request_token, "NetworkId": network_id, "MemberId": member_id, "NodeConfiguration": node_configuration, "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.managedblockchain.get_node(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, network_id: Text, node_id: Text, member_id: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a node that your AWS account owns. All data on the node is lost and cannot be recovered. Applies to
    Hyperledger Fabric and Ethereum.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        network_id(Text): The unique identifier of the network that the node is on. Ethereum public networks have the
            following NetworkIds:    n-ethereum-mainnet     n-ethereum-rinkeby     n-ethereum-ropsten.
        member_id(Text, optional): The unique identifier of the member that owns this node. Applies only to Hyperledger Fabric and
            is required for Hyperledger Fabric. Defaults to None.
        node_id(Text): The unique identifier of the node.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.managedblockchain.delete_node(
                ctx,
                
                
                **{"NetworkId": network_id, "MemberId": member_id, "NodeId": node_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.managedblockchain.get_node(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

