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

hub.exec.boto3.client.backup.delete_backup_vault_access_policy
hub.exec.boto3.client.backup.get_backup_vault_access_policy
hub.exec.boto3.client.backup.put_backup_vault_access_policy
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, backup_vault_name: Text, policy: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Sets a resource-based policy that is used to manage access permissions on the target backup vault. Requires a
    backup vault name and an access policy document in JSON format.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        backup_vault_name(Text): The name of a logical container where backups are stored. Backup vaults are identified by names
            that are unique to the account used to create them and the AWS Region where they are created.
            They consist of lowercase letters, numbers, and hyphens.
        policy(Text, optional): The backup vault access policy document in JSON format. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.backup.put_backup_vault_access_policy(
                ctx,
                
                
                **{"BackupVaultName": backup_vault_name, "Policy": policy}
            )
            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.backup.get_backup_vault_access_policy(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, backup_vault_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the policy document that manages permissions on a backup vault.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        backup_vault_name(Text): The name of a logical container where backups are stored. Backup vaults are identified by names
            that are unique to the account used to create them and the AWS Region where they are created.
            They consist of lowercase letters, numbers, and hyphens.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.backup.delete_backup_vault_access_policy(
                ctx,
                
                
                **{"BackupVaultName": backup_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.exec.boto3.client.backup.get_backup_vault_access_policy(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

