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

hub.exec.boto3.client.s3.delete_public_access_block
hub.exec.boto3.client.s3.get_public_access_block
hub.exec.boto3.client.s3.put_public_access_block
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, bucket: Text, public_access_block_configuration: Dict, content_md5: Text = None, expected_bucket_owner: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates or modifies the PublicAccessBlock configuration for an Amazon S3 bucket. To use this operation, you must
    have the s3:PutBucketPublicAccessBlock permission. For more information about Amazon S3 permissions, see
    Specifying Permissions in a Policy.  When Amazon S3 evaluates the PublicAccessBlock configuration for a bucket
    or an object, it checks the PublicAccessBlock configuration for both the bucket (or the bucket that contains the
    object) and the bucket owner's account. If the PublicAccessBlock configurations are different between the bucket
    and the account, Amazon S3 uses the most restrictive combination of the bucket-level and account-level settings.
    For more information about when Amazon S3 considers a bucket or an object public, see The Meaning of "Public".
    Related Resources     GetPublicAccessBlock     DeletePublicAccessBlock     GetBucketPolicyStatus     Using
    Amazon S3 Block Public Access

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        bucket(Text): The name of the Amazon S3 bucket whose PublicAccessBlock configuration you want to set.
        content_md5(Text, optional): The MD5 hash of the PutPublicAccessBlock request body.  For requests made using the Amazon Web
            Services Command Line Interface (CLI) or Amazon Web Services SDKs, this field is calculated
            automatically. Defaults to None.
        public_access_block_configuration(Dict): The PublicAccessBlock configuration that you want to apply to this Amazon S3 bucket. You can
            enable the configuration options in any combination. For more information about when Amazon S3
            considers a bucket or object public, see The Meaning of "Public" in the Amazon S3 User Guide.
        expected_bucket_owner(Text, optional): The account ID of the expected bucket owner. If the bucket is owned by a different account, the
            request will fail with an HTTP 403 (Access Denied) error. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.s3.public_access_block.present:
                - name: value
                - bucket: value
                - public_access_block_configuration: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.s3.public_access_block.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.s3.get_public_access_block(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.s3.put_public_access_block(
                ctx,
                
                
                **{"Bucket": bucket, "ContentMD5": content_md5, "PublicAccessBlockConfiguration": public_access_block_configuration, "ExpectedBucketOwner": expected_bucket_owner}
            )
            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.s3.get_public_access_block(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, bucket: Text, expected_bucket_owner: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Removes the PublicAccessBlock configuration for an Amazon S3 bucket. To use this operation, you must have the
    s3:PutBucketPublicAccessBlock permission. For more information about permissions, see Permissions Related to
    Bucket Subresource Operations and Managing Access Permissions to Your Amazon S3 Resources. The following
    operations are related to DeletePublicAccessBlock:    Using Amazon S3 Block Public Access
    GetPublicAccessBlock     PutPublicAccessBlock     GetBucketPolicyStatus

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        bucket(Text): The Amazon S3 bucket whose PublicAccessBlock configuration you want to delete.
        expected_bucket_owner(Text, optional): The account ID of the expected bucket owner. If the bucket is owned by a different account, the
            request will fail with an HTTP 403 (Access Denied) error. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

