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

hub.exec.boto3.client.guardduty.create_members
hub.exec.boto3.client.guardduty.delete_members
hub.exec.boto3.client.guardduty.disassociate_members
hub.exec.boto3.client.guardduty.get_members
hub.exec.boto3.client.guardduty.invite_members
hub.exec.boto3.client.guardduty.list_members
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, detector_id: Text, account_details: List)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates member accounts of the current AWS account by specifying a list of AWS account IDs. This step is a
    prerequisite for managing the associated member accounts either by invitation or through an organization. When
    using Create Members as an organizations delegated administrator this action will enable GuardDuty in the added
    member accounts, with the exception of the organization delegated administrator account, which must enable
    GuardDuty prior to being added as a member. If you are adding accounts by invitation use this action after
    GuardDuty has been enabled in potential member accounts and before using  Invite Members .

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        detector_id(Text): The unique ID of the detector of the GuardDuty account that you want to associate member
            accounts with.
        account_details(List): A list of account ID and email address pairs of the accounts that you want to associate with the
            GuardDuty administrator account.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.guardduty.create_members(
                ctx,
                
                
                **{"DetectorId": detector_id, "AccountDetails": account_details}
            )
            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.guardduty.get_members(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, detector_id: Text, account_ids: List)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes GuardDuty member accounts (to the current GuardDuty administrator account) specified by the account IDs.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        detector_id(Text): The unique ID of the detector of the GuardDuty account whose members you want to delete.
        account_ids(List): A list of account IDs of the GuardDuty member accounts that you want to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

