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

hub.exec.boto3.client.lightsail.create_bucket
hub.exec.boto3.client.lightsail.delete_bucket
hub.exec.boto3.client.lightsail.get_buckets
hub.exec.boto3.client.lightsail.update_bucket
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, bucket_name: Text, bundle_id: Text, tags: List = None, enable_object_versioning: bool = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates an Amazon Lightsail bucket. A bucket is a cloud storage resource available in the Lightsail object
    storage service. Use buckets to store objects such as data and its descriptive metadata. For more information
    about buckets, see Buckets in Amazon Lightsail in the Amazon Lightsail Developer Guide.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        bucket_name(Text): The name for the bucket. For more information about bucket names, see Bucket naming rules in
            Amazon Lightsail in the Amazon Lightsail Developer Guide.
        bundle_id(Text): The ID of the bundle to use for the bucket. A bucket bundle specifies the monthly cost, storage
            space, and data transfer quota for a bucket. Use the GetBucketBundles action to get a list of
            bundle IDs that you can specify. Use the UpdateBucketBundle action to change the bundle after
            the bucket is created.
        tags(List, optional): The tag keys and optional values to add to the bucket during creation. Use the TagResource
            action to tag the bucket after it's created. Defaults to None.
        enable_object_versioning(bool, optional): A Boolean value that indicates whether to enable versioning of objects in the bucket. For more
            information about versioning, see Enabling and suspending object versioning in a bucket in
            Amazon Lightsail in the Amazon Lightsail Developer Guide. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.lightsail.create_bucket(
                ctx,
                
                
                **{"bucketName": bucket_name, "bundleId": bundle_id, "tags": tags, "enableObjectVersioning": enable_object_versioning}
            )
            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.lightsail.get_buckets(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, bucket_name: Text, force_delete: bool = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a Amazon Lightsail bucket.  When you delete your bucket, the bucket name is released and can be reused
    for a new bucket in your account or another AWS account.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        bucket_name(Text): The name of the bucket to delete. Use the GetBuckets action to get a list of bucket names that
            you can specify.
        force_delete(bool, optional): A Boolean value that indicates whether to force delete the bucket. You must force delete the
            bucket if it has one of the following conditions:   The bucket is the origin of a distribution.
            The bucket has instances that were granted access to it using the SetResourceAccessForBucket
            action.   The bucket has objects.   The bucket has access keys.    Force deleting a bucket might
            impact other resources that rely on the bucket, such as instances, distributions, or software
            that use the issued access keys. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.lightsail.delete_bucket(
                ctx,
                
                
                **{"bucketName": bucket_name, "forceDelete": force_delete}
            )
            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.lightsail.get_buckets(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

