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

hub.exec.boto3.client.detective.create_members
hub.exec.boto3.client.detective.delete_members
hub.exec.boto3.client.detective.get_members
hub.exec.boto3.client.detective.list_members
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, graph_arn: Text, accounts: List, message: Text = None, disable_email_notification: bool = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Sends a request to invite the specified AWS accounts to be member accounts in the behavior graph. This operation
    can only be called by the administrator account for a behavior graph.   CreateMembers verifies the accounts and
    then invites the verified accounts. The administrator can optionally specify to not send invitation emails to
    the member accounts. This would be used when the administrator manages their member accounts centrally. The
    request provides the behavior graph ARN and the list of accounts to invite. The response separates the requested
    accounts into two lists:   The accounts that CreateMembers was able to start the verification for. This list
    includes member accounts that are being verified, that have passed verification and are to be invited, and that
    have failed verification.   The accounts that CreateMembers was unable to process. This list includes accounts
    that were already invited to be member accounts in the behavior graph.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        graph_arn(Text): The ARN of the behavior graph to invite the member accounts to contribute their data to.
        message(Text, optional): Customized message text to include in the invitation email message to the invited member
            accounts. Defaults to None.
        disable_email_notification(bool, optional): if set to true, then the member accounts do not receive email notifications. By default, this is
            set to false, and the member accounts receive email notifications. Defaults to None.
        accounts(List): The list of AWS accounts to invite to become member accounts in the behavior graph. You can
            invite up to 50 accounts at a time. For each invited account, the account list contains the
            account identifier and the AWS account root user email address.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

async def absent(hub, ctx, name: Text, graph_arn: Text, account_ids: List)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes one or more member accounts from the administrator account's behavior graph. This operation can only be
    called by a Detective administrator account. That account cannot use DeleteMembers to delete their own account
    from the behavior graph. To disable a behavior graph, the administrator account uses the DeleteGraph API method.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        graph_arn(Text): The ARN of the behavior graph to delete members from.
        account_ids(List): The list of AWS account identifiers for the member accounts to delete from the behavior graph.
            You can delete up to 50 member accounts at a time.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

