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

hub.exec.boto3.client.fsx.copy_backup
hub.exec.boto3.client.fsx.create_backup
hub.exec.boto3.client.fsx.delete_backup
hub.exec.boto3.client.fsx.describe_backups
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, file_system_id: Text, client_request_token: Text = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a backup of an existing Amazon FSx file system. Creating regular backups for your file system is a best
    practice, enabling you to restore a file system from a backup if an issue arises with the original file system.
    For Amazon FSx for Lustre file systems, you can create a backup only for file systems with the following
    configuration:   a Persistent deployment type   is not linked to a data respository.   For more information
    about backing up Amazon FSx for Lustre file systems, see Working with FSx for Lustre backups. For more
    information about backing up Amazon FSx for Windows file systems, see Working with FSx for Windows backups. If a
    backup with the specified client request token exists, and the parameters match, this operation returns the
    description of the existing backup. If a backup specified client request token exists, and the parameters don't
    match, this operation returns IncompatibleParameterError. If a backup with the specified client request token
    doesn't exist, CreateBackup does the following:    Creates a new Amazon FSx backup with an assigned ID, and an
    initial lifecycle state of CREATING.   Returns the description of the backup.   By using the idempotent
    operation, you can retry a CreateBackup operation without the risk of creating an extra backup. This approach
    can be useful when an initial call fails in a way that makes it unclear whether a backup was created. If you use
    the same client request token and the initial call created a backup, the operation returns a successful result
    because all the parameters are the same. The CreateBackup operation returns while the backup's lifecycle state
    is still CREATING. You can check the backup creation status by calling the DescribeBackups operation, which
    returns the backup state along with other information.

    Args:
        name(Text): The name of the state.
        file_system_id(Text): The ID of the file system to back up.
        client_request_token(Text, optional): (Optional) A string of up to 64 ASCII characters that Amazon FSx uses to ensure idempotent
            creation. This string is automatically filled on your behalf when you use the AWS Command Line
            Interface (AWS CLI) or an AWS SDK. Defaults to None.
        tags(List, optional): (Optional) The tags to apply to the backup at backup creation. The key value of the Name tag
            appears in the console as the backup name. If you have set CopyTagsToBackups to true, and you
            specify one or more tags using the CreateBackup action, no existing file system tags are copied
            from the file system to the backup. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.fsx.backup.present:
                - name: value
                - file_system_id: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)

    
    before = await hub.exec.boto3.client.fsx.describe_backups(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.fsx.create_backup(
                ctx,
                
                
                **{"FileSystemId": file_system_id, "ClientRequestToken": client_request_token, "Tags": tags}
            )
            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.fsx.describe_backups(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, backup_id: Text, client_request_token: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes an Amazon FSx backup, deleting its contents. After deletion, the backup no longer exists, and its data
    is gone. The DeleteBackup call returns instantly. The backup will not show up in later DescribeBackups calls.
    The data in a deleted backup is also deleted and can't be recovered by any means.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        backup_id(Text): The ID of the backup you want to delete.
        client_request_token(Text, optional): A string of up to 64 ASCII characters that Amazon FSx uses to ensure idempotent deletion. This
            is automatically filled on your behalf when using the AWS CLI or SDK. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.fsx.delete_backup(
                ctx,
                
                
                **{"BackupId": backup_id, "ClientRequestToken": client_request_token}
            )
            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.fsx.describe_backups(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

