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

hub.exec.boto3.client.s3.delete_bucket_ownership_controls
hub.exec.boto3.client.s3.get_bucket_ownership_controls
hub.exec.boto3.client.s3.put_bucket_ownership_controls
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, bucket: Text, ownership_controls: Dict, content_md5: Text = None, expected_bucket_owner: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates or modifies OwnershipControls for an Amazon S3 bucket. To use this operation, you must have the
    s3:PutBucketOwnershipControls permission. For more information about Amazon S3 permissions, see Specifying
    Permissions in a Policy.  For information about Amazon S3 Object Ownership, see Using Object Ownership.  The
    following operations are related to PutBucketOwnershipControls:    GetBucketOwnershipControls
    DeleteBucketOwnershipControls

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        bucket(Text): The name of the Amazon S3 bucket whose OwnershipControls you want to set.
        content_md5(Text, optional): The MD5 hash of the OwnershipControls 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.
        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.
        ownership_controls(Dict): The OwnershipControls (BucketOwnerPreferred or ObjectWriter) that you want to apply to this
            Amazon S3 bucket.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.s3.put_bucket_ownership_controls(
                ctx,
                
                
                **{"Bucket": bucket, "ContentMD5": content_md5, "ExpectedBucketOwner": expected_bucket_owner, "OwnershipControls": ownership_controls}
            )
            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_bucket_ownership_controls(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 OwnershipControls for an Amazon S3 bucket. To use this operation, you must have the
    s3:PutBucketOwnershipControls permission. For more information about Amazon S3 permissions, see Specifying
    Permissions in a Policy. For information about Amazon S3 Object Ownership, see Using Object Ownership.  The
    following operations are related to DeleteBucketOwnershipControls:    GetBucketOwnershipControls
    PutBucketOwnershipControls

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        bucket(Text): The Amazon S3 bucket whose OwnershipControls 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.bucket_ownership_control.absent:
                - name: value
                - bucket: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.s3.bucket_ownership_control.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_bucket_ownership_controls(name)

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

