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

hub.exec.boto3.client.lightsail.create_instance_snapshot
hub.exec.boto3.client.lightsail.delete_instance_snapshot
hub.exec.boto3.client.lightsail.get_instance_snapshots
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, instance_snapshot_name: Text, instance_name: Text, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a snapshot of a specific virtual private server, or instance. You can use a snapshot to create a new
    instance that is based on that snapshot. The create instance 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.
        instance_snapshot_name(Text): The name for your new snapshot.
        instance_name(Text): The Lightsail instance on which to base your snapshot.
        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.instance_snapshot.present:
                - name: value
                - instance_snapshot_name: value
                - instance_name: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.lightsail.instance_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_instance_snapshots(name)

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

async def absent(hub, ctx, name: Text, instance_snapshot_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a specific snapshot of a virtual private server (or instance). The delete instance snapshot operation
    supports tag-based access control via resource tags applied to the resource identified by instance 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.
        instance_snapshot_name(Text): The name of the snapshot to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

