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

hub.exec.boto3.client.s3.delete_object_tagging
hub.exec.boto3.client.s3.get_object_tagging
hub.exec.boto3.client.s3.put_object_tagging
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, bucket: Text, key: Text, tagging: Dict, version_id: Text = None, content_md5: Text = None, expected_bucket_owner: Text = None, request_payer: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Sets the supplied tag-set to an object that already exists in a bucket. A tag is a key-value pair. You can
    associate tags with an object by sending a PUT request against the tagging subresource that is associated with
    the object. You can retrieve tags by sending a GET request. For more information, see GetObjectTagging. For
    tagging-related restrictions related to characters and encodings, see Tag Restrictions. Note that Amazon S3
    limits the maximum number of tags to 10 tags per object. To use this operation, you must have permission to
    perform the s3:PutObjectTagging action. By default, the bucket owner has this permission and can grant this
    permission to others. To put tags of any other version, use the versionId query parameter. You also need
    permission for the s3:PutObjectVersionTagging action. For information about the Amazon S3 object tagging
    feature, see Object Tagging.  Special Errors       Code: InvalidTagError      Cause: The tag provided was not a
    valid tag. This error can occur if the tag did not pass input validation. For more information, see Object
    Tagging.         Code: MalformedXMLError      Cause: The XML provided does not match the schema.         Code:
    OperationAbortedError      Cause: A conflicting conditional action is currently in progress against this
    resource. Please try again.         Code: InternalError     Cause: The service was unable to apply the provided
    tag to the object.       Related Resources     GetObjectTagging     DeleteObjectTagging

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        bucket(Text): The bucket name containing the object.  When using this action with an access point, you must
            direct requests to the access point hostname. The access point hostname takes the form
            AccessPointName-AccountId.s3-accesspoint.Region.amazonaws.com. When using this action with an
            access point through the Amazon Web Services SDKs, you provide the access point ARN in place of
            the bucket name. For more information about access point ARNs, see Using access points in the
            Amazon S3 User Guide. When using this action with Amazon S3 on Outposts, you must direct
            requests to the S3 on Outposts hostname. The S3 on Outposts hostname takes the form
            AccessPointName-AccountId.outpostID.s3-outposts.Region.amazonaws.com. When using this action
            using S3 on Outposts through the Amazon Web Services SDKs, you provide the Outposts bucket ARN
            in place of the bucket name. For more information about S3 on Outposts ARNs, see Using S3 on
            Outposts in the Amazon S3 User Guide.
        key(Text): Name of the object key.
        version_id(Text, optional): The versionId of the object that the tag-set will be added to. Defaults to None.
        content_md5(Text, optional): The MD5 hash for the 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.
        tagging(Dict): Container for the TagSet and Tag elements.
        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.
        request_payer(Text, optional): Confirms that the requester knows that they will be charged for the request. Bucket owners need
            not specify this parameter in their requests. For information about downloading objects from
            requester pays buckets, see Downloading Objects in Requestor Pays Buckets in the Amazon S3 User
            Guide. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.s3.put_object_tagging(
                ctx,
                
                
                **{"Bucket": bucket, "Key": key, "VersionId": version_id, "ContentMD5": content_md5, "Tagging": tagging, "ExpectedBucketOwner": expected_bucket_owner, "RequestPayer": request_payer}
            )
            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_object_tagging(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, bucket: Text, key: Text, version_id: Text = None, expected_bucket_owner: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Removes the entire tag set from the specified object. For more information about managing object tags, see
    Object Tagging. To use this operation, you must have permission to perform the s3:DeleteObjectTagging action. To
    delete tags of a specific object version, add the versionId query parameter in the request. You will need
    permission for the s3:DeleteObjectVersionTagging action. The following operations are related to
    DeleteBucketMetricsConfiguration:    PutObjectTagging     GetObjectTagging

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        bucket(Text): The bucket name containing the objects from which to remove the tags.  When using this action
            with an access point, you must direct requests to the access point hostname. The access point
            hostname takes the form AccessPointName-AccountId.s3-accesspoint.Region.amazonaws.com. When
            using this action with an access point through the Amazon Web Services SDKs, you provide the
            access point ARN in place of the bucket name. For more information about access point ARNs, see
            Using access points in the Amazon S3 User Guide. When using this action with Amazon S3 on
            Outposts, you must direct requests to the S3 on Outposts hostname. The S3 on Outposts hostname
            takes the form AccessPointName-AccountId.outpostID.s3-outposts.Region.amazonaws.com. When using
            this action using S3 on Outposts through the Amazon Web Services SDKs, you provide the Outposts
            bucket ARN in place of the bucket name. For more information about S3 on Outposts ARNs, see
            Using S3 on Outposts in the Amazon S3 User Guide.
        key(Text): The key that identifies the object in the bucket from which to remove all tags.
        version_id(Text, optional): The versionId of the object that the tag-set will be removed from. 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.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

