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

hub.exec.boto3.client.lightsail.create_disk_snapshot
hub.exec.boto3.client.lightsail.delete_disk_snapshot
hub.exec.boto3.client.lightsail.get_disk_snapshots
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, disk_snapshot_name: Text, disk_name: Text = None, instance_name: Text = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a snapshot of a block storage disk. You can use snapshots for backups, to make copies of disks, and to
    save data before shutting down a Lightsail instance. You can take a snapshot of an attached disk that is in use;
    however, snapshots only capture data that has been written to your disk at the time the snapshot command is
    issued. This may exclude any data that has been cached by any applications or the operating system. If you can
    pause any file systems on the disk long enough to take a snapshot, your snapshot should be complete.
    Nevertheless, if you cannot pause all file writes to the disk, you should unmount the disk from within the
    Lightsail instance, issue the create disk snapshot command, and then remount the disk to ensure a consistent and
    complete snapshot. You may remount and use your disk while the snapshot status is pending. You can also use this
    operation to create a snapshot of an instance's system volume. You might want to do this, for example, to
    recover data from the system volume of a botched instance or to create a backup of the system volume like you
    would for a block storage disk. To create a snapshot of a system volume, just define the instance name parameter
    when issuing the snapshot command, and a snapshot of the defined instance's system volume will be created. After
    the snapshot is available, you can create a block storage disk from the snapshot and attach it to a running
    instance to access the data on the disk. The create disk snapshot operation supports tag-based access control
    via request tags. For more information, see the Amazon Lightsail Developer Guide.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        disk_name(Text, optional): The unique name of the source disk (e.g., Disk-Virginia-1).  This parameter cannot be defined
            together with the instance name parameter. The disk name and instance name parameters are
            mutually exclusive. Defaults to None.
        disk_snapshot_name(Text): The name of the destination disk snapshot (e.g., my-disk-snapshot) based on the source disk.
        instance_name(Text, optional): The unique name of the source instance (e.g., Amazon_Linux-512MB-Virginia-1). When this is
            defined, a snapshot of the instance's system volume is created.  This parameter cannot be
            defined together with the disk name parameter. The instance name and disk name parameters are
            mutually exclusive. Defaults to None.
        tags(List, optional): The tag keys and optional values to add to the resource during create. Use the TagResource
            action to tag a resource after it's created. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.lightsail.create_disk_snapshot(
                ctx,
                
                
                **{"diskName": disk_name, "diskSnapshotName": disk_snapshot_name, "instanceName": instance_name, "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.lightsail.get_disk_snapshots(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, disk_snapshot_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified disk snapshot. When you make periodic snapshots of a disk, the snapshots are incremental,
    and only the blocks on the device that have changed since your last snapshot are saved in the new snapshot. When
    you delete a snapshot, only the data not needed for any other snapshot is removed. So regardless of which prior
    snapshots have been deleted, all active snapshots will have access to all the information needed to restore the
    disk. The delete disk snapshot operation supports tag-based access control via resource tags applied to the
    resource identified by disk snapshot name. For more information, see the Amazon Lightsail Developer Guide.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        disk_snapshot_name(Text): The name of the disk snapshot you want to delete (e.g., my-disk-snapshot).

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

