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

hub.exec.boto3.client.detective.accept_invitation
hub.exec.boto3.client.detective.list_invitations
hub.exec.boto3.client.detective.reject_invitation
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, graph_arn: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Accepts an invitation for the member account to contribute data to a behavior graph. This operation can only be
    called by an invited member account.  The request provides the ARN of behavior graph. The member account status
    in the graph must be INVITED.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        graph_arn(Text): The ARN of the behavior graph that the member account is accepting the invitation for. The
            member account status in the behavior graph must be INVITED.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.detective.accept_invitation(
                ctx,
                
                
                **{"GraphArn": graph_arn}
            )
            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.detective.list_invitations(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, graph_arn: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Rejects an invitation to contribute the account data to a behavior graph. This operation must be called by a
    member account that has the INVITED status.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        graph_arn(Text): The ARN of the behavior graph to reject the invitation to. The member account's current member
            status in the behavior graph must be INVITED.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

