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

hub.exec.boto3.client.s3control.create_bucket
hub.exec.boto3.client.s3control.delete_bucket
hub.exec.boto3.client.s3control.get_bucket
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, bucket: Text, acl: Text = None, create_bucket_configuration: Dict = None, grant_full_control: Text = None, grant_read: Text = None, grant_read_acp: Text = None, grant_write: Text = None, grant_write_acp: Text = None, object_lock_enabled_for_bucket: bool = None, outpost_id: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
     This action creates an Amazon S3 on Outposts bucket. To create an S3 bucket, see Create Bucket in the Amazon S3
    API Reference.   Creates a new Outposts bucket. By creating the bucket, you become the bucket owner. To create
    an Outposts bucket, you must have S3 on Outposts. For more information, see Using Amazon S3 on Outposts in
    Amazon S3 User Guide. Not every string is an acceptable bucket name. For information on bucket naming
    restrictions, see Working with Amazon S3 Buckets. S3 on Outposts buckets support:   Tags
    LifecycleConfigurations for deleting expired objects   For a complete list of restrictions and Amazon S3 feature
    limitations on S3 on Outposts, see  Amazon S3 on Outposts Restrictions and Limitations. For an example of the
    request syntax for Amazon S3 on Outposts that uses the S3 on Outposts endpoint hostname prefix and x-amz-
    outpost-id in your API request, see the Examples section. The following actions are related to CreateBucket for
    Amazon S3 on Outposts:    PutObject     GetBucket     DeleteBucket     CreateAccessPoint
    PutAccessPointPolicy

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        acl(Text, optional): The canned ACL to apply to the bucket.  This is not supported by Amazon S3 on Outposts buckets. Defaults to None.
        bucket(Text): The name of the bucket.
        create_bucket_configuration(Dict, optional): The configuration information for the bucket.  This is not supported by Amazon S3 on Outposts
            buckets. Defaults to None.
        grant_full_control(Text, optional): Allows grantee the read, write, read ACP, and write ACP permissions on the bucket.  This is not
            supported by Amazon S3 on Outposts buckets. Defaults to None.
        grant_read(Text, optional): Allows grantee to list the objects in the bucket.  This is not supported by Amazon S3 on
            Outposts buckets. Defaults to None.
        grant_read_acp(Text, optional): Allows grantee to read the bucket ACL.  This is not supported by Amazon S3 on Outposts buckets. Defaults to None.
        grant_write(Text, optional): Allows grantee to create, overwrite, and delete any object in the bucket.  This is not supported
            by Amazon S3 on Outposts buckets. Defaults to None.
        grant_write_acp(Text, optional): Allows grantee to write the ACL for the applicable bucket.  This is not supported by Amazon S3
            on Outposts buckets. Defaults to None.
        object_lock_enabled_for_bucket(bool, optional): Specifies whether you want S3 Object Lock to be enabled for the new bucket.  This is not
            supported by Amazon S3 on Outposts buckets. Defaults to None.
        outpost_id(Text, optional): The ID of the Outposts where the bucket is being created.  This is required by Amazon S3 on
            Outposts buckets. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.s3control.create_bucket(
                ctx,
                
                
                **{"ACL": acl, "Bucket": bucket, "CreateBucketConfiguration": create_bucket_configuration, "GrantFullControl": grant_full_control, "GrantRead": grant_read, "GrantReadACP": grant_read_acp, "GrantWrite": grant_write, "GrantWriteACP": grant_write_acp, "ObjectLockEnabledForBucket": object_lock_enabled_for_bucket, "OutpostId": outpost_id}
            )
            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.s3control.get_bucket(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, account_id: Text, bucket: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
     This action deletes an Amazon S3 on Outposts bucket. To delete an S3 bucket, see DeleteBucket in the Amazon S3
    API Reference.   Deletes the Amazon S3 on Outposts bucket. All objects (including all object versions and delete
    markers) in the bucket must be deleted before the bucket itself can be deleted. For more information, see Using
    Amazon S3 on Outposts in Amazon S3 User Guide. All Amazon S3 on Outposts REST API requests for this action
    require an additional parameter of x-amz-outpost-id to be passed with the request and an S3 on Outposts endpoint
    hostname prefix instead of s3-control. For an example of the request syntax for Amazon S3 on Outposts that uses
    the S3 on Outposts endpoint hostname prefix and the x-amz-outpost-id derived using the access point ARN, see the
    Examples section.  Related Resources     CreateBucket     GetBucket     DeleteObject

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        account_id(Text): The account ID that owns the Outposts bucket.
        bucket(Text): Specifies the bucket being deleted. For using this parameter with Amazon S3 on Outposts with the
            REST API, you must specify the name and the x-amz-outpost-id as well. For using this parameter
            with S3 on Outposts with the Amazon Web Services SDK and CLI, you must specify the ARN of the
            bucket accessed in the format arn:aws:s3-outposts:<Region>:<account-id>:outpost/<outpost-
            id>/bucket/<my-bucket-name>. For example, to access the bucket reports through outpost my-
            outpost owned by account 123456789012 in Region us-west-2, use the URL encoding of
            arn:aws:s3-outposts:us-west-2:123456789012:outpost/my-outpost/bucket/reports. The value must be
            URL encoded.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

