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

hub.exec.boto3.client.glacier.create_vault
hub.exec.boto3.client.glacier.delete_vault
hub.exec.boto3.client.glacier.describe_vault
hub.exec.boto3.client.glacier.list_vaults
resource = hub.tool.boto3.resource.create(ctx, "glacier", "Vault", name)
hub.tool.boto3.resource.exec(resource, create, *args, **kwargs)
hub.tool.boto3.resource.exec(resource, delete, *args, **kwargs)
hub.tool.boto3.resource.exec(resource, initiate_inventory_retrieval, *args, **kwargs)
hub.tool.boto3.resource.exec(resource, initiate_multipart_upload, *args, **kwargs)
hub.tool.boto3.resource.exec(resource, upload_archive, *args, **kwargs)
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, account_id: Text, vault_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    This operation creates a new vault with the specified name. The name of the vault must be unique within a region
    for an AWS account. You can create up to 1,000 vaults per account. If you need to create more vaults, contact
    Amazon S3 Glacier. You must use the following guidelines when naming a vault.   Names can be between 1 and 255
    characters long.   Allowed characters are a-z, A-Z, 0-9, '_' (underscore), '-' (hyphen), and '.' (period).
    This operation is idempotent. An AWS account has full permission to perform all operations (actions). However,
    AWS Identity and Access Management (IAM) users don't have any permissions by default. You must grant them
    explicit permission to perform specific actions. For more information, see Access Control Using AWS Identity and
    Access Management (IAM).  For conceptual information and underlying REST API, see Creating a Vault in Amazon
    Glacier and Create Vault  in the Amazon Glacier Developer Guide.

    Args:
        name(Text): The name of the state.
        account_id(Text): The AccountId value is the AWS account ID. This value must match the AWS account ID associated
            with the credentials used to sign the request. You can either specify an AWS account ID or
            optionally a single '-' (hyphen), in which case Amazon S3 Glacier uses the AWS account ID
            associated with the credentials used to sign the request. If you specify your account ID, do not
            include any hyphens ('-') in the ID.
        vault_name(Text): The name of the vault.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.glacier.vault.present:
                - name: value
                - account_id: value
                - vault_name: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)

    resource = hub.tool.boto3.resource.create(ctx, "glacier", "Vault", name)
    before = await hub.tool.boto3.resource.describe(resource)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.glacier.create_vault(
                ctx,
                
                
                **{"accountId": account_id, "vaultName": vault_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.tool.boto3.resource.describe(resource)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, account_id: Text, vault_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    This operation deletes a vault. Amazon S3 Glacier will delete a vault only if there are no archives in the vault
    as of the last inventory and there have been no writes to the vault since the last inventory. If either of these
    conditions is not satisfied, the vault deletion fails (that is, the vault is not removed) and Amazon S3 Glacier
    returns an error. You can use DescribeVault to return the number of archives in a vault, and you can use
    Initiate a Job (POST jobs) to initiate a new inventory retrieval for a vault. The inventory contains the archive
    IDs you use to delete archives using Delete Archive (DELETE archive). This operation is idempotent. An AWS
    account has full permission to perform all operations (actions). However, AWS Identity and Access Management
    (IAM) users don't have any permissions by default. You must grant them explicit permission to perform specific
    actions. For more information, see Access Control Using AWS Identity and Access Management (IAM).  For
    conceptual information and underlying REST API, see Deleting a Vault in Amazon Glacier and Delete Vault  in the
    Amazon S3 Glacier Developer Guide.

    Args:
        name(Text): The name of the state.
        account_id(Text): The AccountId value is the AWS account ID of the account that owns the vault. You can either
            specify an AWS account ID or optionally a single '-' (hyphen), in which case Amazon S3 Glacier
            uses the AWS account ID associated with the credentials used to sign the request. If you use an
            account ID, do not include any hyphens ('-') in the ID.
        vault_name(Text): The name of the vault.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.glacier.vault.absent:
                - name: value
                - account_id: value
                - vault_name: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)

    resource = hub.tool.boto3.resource.create(ctx, "glacier", "Vault", name)

    before = await hub.tool.boto3.resource.describe(resource)

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.glacier.delete_vault(
                ctx,
                
                
                **{"accountId": account_id, "vaultName": vault_name}
            )
            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.tool.boto3.resource.describe(resource)
    result["changes"] = differ.deep_diff(before, after)
    return result

