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

hub.exec.boto3.client.macie2.create_member
hub.exec.boto3.client.macie2.delete_member
hub.exec.boto3.client.macie2.disassociate_member
hub.exec.boto3.client.macie2.get_member
hub.exec.boto3.client.macie2.list_members
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, account: Dict, tags: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Associates an account with an Amazon Macie administrator account.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        account(Dict): The details of the account to associate with the administrator account.
        tags(Dict, optional): A map of key-value pairs that specifies the tags to associate with the account in Amazon Macie.
            An account can have a maximum of 50 tags. Each tag consists of a tag key and an associated tag
            value. The maximum length of a tag key is 128 characters. The maximum length of a tag value is
            256 characters. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

async def absent(hub, ctx, name: Text, id_: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the association between an Amazon Macie administrator account and an account.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        id_(Text): The unique identifier for the Amazon Macie resource or account that the request applies to.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

