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

hub.exec.boto3.client.securityhub.accept_invitation
hub.exec.boto3.client.securityhub.decline_invitations
hub.exec.boto3.client.securityhub.delete_invitations
hub.exec.boto3.client.securityhub.list_invitations
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, master_id: Text, invitation_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    This method is deprecated. Instead, use AcceptAdministratorInvitation. The Security Hub console continues to use
    AcceptInvitation. It will eventually change to use AcceptAdministratorInvitation. Any IAM policies that
    specifically control access to this function must continue to use AcceptInvitation. You should also add
    AcceptAdministratorInvitation to your policies to ensure that the correct permissions are in place after the
    console begins to use AcceptAdministratorInvitation. Accepts the invitation to be a member account and be
    monitored by the Security Hub administrator account that the invitation was sent from. This operation is only
    used by member accounts that are not added through Organizations. When the member account accepts the
    invitation, permission is granted to the administrator account to view findings generated in the member account.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        master_id(Text): The account ID of the Security Hub administrator account that sent the invitation.
        invitation_id(Text): The identifier of the invitation sent from the Security Hub administrator account.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.securityhub.accept_invitation(
                ctx,
                
                
                **{"MasterId": master_id, "InvitationId": invitation_id}
            )
            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.securityhub.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 invitations received by the Amazon Web Services account to become a member account. This operation is
    only used by accounts that are not part of an organization. Organization accounts do not receive invitations.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        account_ids(List): The list of the account IDs that sent the invitations to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

