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

hub.exec.boto3.client.macie.associate_s3_resources
hub.exec.boto3.client.macie.disassociate_s3_resources
hub.exec.boto3.client.macie.list_s3_resources
hub.exec.boto3.client.macie.update_s3_resources
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, s3_resources: List, member_account_id: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Associates specified S3 resources with Amazon Macie Classic for monitoring and data classification. If
    memberAccountId isn't specified, the action associates specified S3 resources with Macie Classic for the current
    Macie Classic administrator account. If memberAccountId is specified, the action associates specified S3
    resources with Macie Classic for the specified member account.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        member_account_id(Text, optional): The ID of the Amazon Macie Classic member account whose resources you want to associate with
            Macie Classic. Defaults to None.
        s3_resources(List): The S3 resources that you want to associate with Amazon Macie Classic for monitoring and data
            classification.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.macie.associate_s3_resources(
                ctx,
                
                
                **{"memberAccountId": member_account_id, "s3Resources": s3_resources}
            )
            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.macie.list_s3_resources(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, associated_s3_resources: List, member_account_id: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Removes specified S3 resources from being monitored by Amazon Macie Classic. If memberAccountId isn't specified,
    the action removes specified S3 resources from Macie Classic for the current Macie Classic administrator
    account. If memberAccountId is specified, the action removes specified S3 resources from Macie Classic for the
    specified member account.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        member_account_id(Text, optional): The ID of the Amazon Macie Classic member account whose resources you want to remove from being
            monitored by Macie Classic. Defaults to None.
        associated_s3_resources(List): The S3 resources (buckets or prefixes) that you want to remove from being monitored and
            classified by Amazon Macie Classic.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

