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

hub.exec.boto3.client.lightsail.create_bucket_access_key
hub.exec.boto3.client.lightsail.delete_bucket_access_key
hub.exec.boto3.client.lightsail.get_bucket_access_keys
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, bucket_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a new access key for the specified Amazon Lightsail bucket. Access keys consist of an access key ID and
    corresponding secret access key. Access keys grant full programmatic access to the specified bucket and its
    objects. You can have a maximum of two access keys per bucket. Use the GetBucketAccessKeys action to get a list
    of current access keys for a specific bucket. For more information about access keys, see Creating access keys
    for a bucket in Amazon Lightsail in the Amazon Lightsail Developer Guide.  The secretAccessKey value is returned
    only in response to the CreateBucketAccessKey action. You can get a secret access key only when you first create
    an access key; you cannot get the secret access key later. If you lose the secret access key, you must create a
    new access key.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        bucket_name(Text): The name of the bucket that the new access key will belong to, and grant access to.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

async def absent(hub, ctx, name: Text, bucket_name: Text, access_key_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes an access key for the specified Amazon Lightsail bucket. We recommend that you delete an access key if
    the secret access key is compromised. For more information about access keys, see Creating access keys for a
    bucket 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 of the bucket that the access key belongs to.
        access_key_id(Text): The ID of the access key to delete. Use the GetBucketAccessKeys action to get a list of access
            key IDs that you can specify.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

