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

hub.exec.boto3.client.managedblockchain.create_member
hub.exec.boto3.client.managedblockchain.delete_member
hub.exec.boto3.client.managedblockchain.get_member
hub.exec.boto3.client.managedblockchain.list_members
hub.exec.boto3.client.managedblockchain.update_member
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, client_request_token: Text, invitation_id: Text, network_id: Text, member_configuration: Dict)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a member within a Managed Blockchain network. Applies only to Hyperledger Fabric.

    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.
        invitation_id(Text): The unique identifier of the invitation that is sent to the member to join the network.
        network_id(Text): The unique identifier of the network in which the member is created.
        member_configuration(Dict): Member configuration parameters.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

async def absent(hub, ctx, name: Text, network_id: Text, member_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a member. Deleting a member removes the member and all associated resources from the network.
    DeleteMember can only be called for a specified MemberId if the principal performing the action is associated
    with the AWS account that owns the member. In all other cases, the DeleteMember action is carried out as the
    result of an approved proposal to remove a member. If MemberId is the last member in a network specified by the
    last AWS account, the network is deleted also. Applies only to Hyperledger Fabric.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        network_id(Text): The unique identifier of the network from which the member is removed.
        member_id(Text): The unique identifier of the member to remove.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

