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

hub.exec.boto3.client.macie2.accept_invitation
hub.exec.boto3.client.macie2.create_invitations
hub.exec.boto3.client.macie2.decline_invitations
hub.exec.boto3.client.macie2.delete_invitations
hub.exec.boto3.client.macie2.list_invitations
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, account_ids: List, disable_email_notification: bool = None, message: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Sends an Amazon Macie membership invitation to one or more accounts.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        account_ids(List): An array that lists Amazon Web Services account IDs, one for each account to send the invitation
            to.
        disable_email_notification(bool, optional): Specifies whether to send an email notification to the root user of each account that the
            invitation will be sent to. This notification is in addition to an alert that the root user
            receives in Personal Health Dashboard. To send an email notification to the root user of each
            account, set this value to true. Defaults to None.
        message(Text, optional): A custom message to include in the invitation. Amazon Macie adds this message to the standard
            content that it sends for an invitation. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

async def absent(hub, ctx, name: Text, account_ids: List)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes Amazon Macie membership invitations that were received from specific accounts.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        account_ids(List): An array that lists Amazon Web Services account IDs, one for each account that sent an
            invitation to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

