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

hub.exec.boto3.client.ec2.copy_snapshot
hub.exec.boto3.client.ec2.create_snapshots
hub.exec.boto3.client.ec2.delete_snapshot
hub.exec.boto3.client.ec2.describe_snapshots
hub.exec.boto3.client.ec2.import_snapshot
resource = hub.tool.boto3.resource.create(ctx, "ec2", "Snapshot", name)
hub.tool.boto3.resource.exec(resource, copy, *args, **kwargs)
hub.tool.boto3.resource.exec(resource, create_tags, *args, **kwargs)
hub.tool.boto3.resource.exec(resource, delete, *args, **kwargs)
hub.tool.boto3.resource.exec(resource, describe_attribute, *args, **kwargs)
hub.tool.boto3.resource.exec(resource, modify_attribute, *args, **kwargs)
hub.tool.boto3.resource.exec(resource, reset_attribute, *args, **kwargs)
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, instance_specification: Dict, description: Text = None, outpost_arn: Text = None, tag_specifications: List = None, copy_tags_from_source: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates crash-consistent snapshots of multiple EBS volumes and stores the data in S3. Volumes are chosen by
    specifying an instance. Any attached volumes will produce one snapshot each that is crash-consistent across the
    instance. Boot volumes can be excluded by changing the parameters.  You can create multi-volume snapshots of
    instances in a Region and instances on an Outpost. If you create snapshots from an instance in a Region, the
    snapshots must be stored in the same Region as the instance. If you create snapshots from an instance on an
    Outpost, the snapshots can be stored on the same Outpost as the instance, or in the Region for that Outpost.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        description(Text, optional):  A description propagated to every snapshot specified by the instance. Defaults to None.
        instance_specification(Dict): The instance to specify which volumes should be included in the snapshots.
        outpost_arn(Text, optional): The Amazon Resource Name (ARN) of the Outpost on which to create the local snapshots.   To
            create snapshots from an instance in a Region, omit this parameter. The snapshots are created in
            the same Region as the instance.   To create snapshots from an instance on an Outpost and store
            the snapshots in the Region, omit this parameter. The snapshots are created in the Region for
            the Outpost.   To create snapshots from an instance on an Outpost and store the snapshots on an
            Outpost, specify the ARN of the destination Outpost. The snapshots must be created on the same
            Outpost as the instance.   For more information, see  Create multi-volume local snapshots from
            instances on an Outpost in the Amazon Elastic Compute Cloud User Guide. Defaults to None.
        tag_specifications(List, optional): Tags to apply to every snapshot specified by the instance. Defaults to None.
        copy_tags_from_source(Text, optional): Copies the tags from the specified volume to corresponding snapshot. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.ec2.snapshot.present:
                - name: value
                - instance_specification: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.ec2.snapshot.id(
        ctx,
        jmes_path=name
    )
    if ret["status"]:
        # name is now the first id that matched the JMES search path
        name = ret["ret"]
    

    resource = hub.tool.boto3.resource.create(ctx, "ec2", "Snapshot", 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.ec2.create_snapshots(
                ctx,
                DryRun=ctx.test,
                
                **{"Description": description, "InstanceSpecification": instance_specification, "OutpostArn": outpost_arn, "TagSpecifications": tag_specifications, "CopyTagsFromSource": copy_tags_from_source}
            )
            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, snapshot_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified snapshot. When you make periodic snapshots of a volume, 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
    volume. You cannot delete a snapshot of the root device of an EBS volume used by a registered AMI. You must
    first de-register the AMI before you can delete the snapshot. For more information, see Delete an Amazon EBS
    snapshot in the Amazon Elastic Compute Cloud User Guide.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        snapshot_id(Text): The ID of the EBS snapshot.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.ec2.snapshot.absent:
                - name: value
                - snapshot_id: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.ec2.snapshot.id(
        ctx,
        jmes_path=name
    )
    if ret["status"]:
        # name is now the first id that matched the JMES search path
        name = ret["ret"]
    

    resource = hub.tool.boto3.resource.create(ctx, "ec2", "Snapshot", 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.ec2.delete_snapshot(
                ctx,
                DryRun=ctx.test,
                
                **{"SnapshotId": snapshot_id}
            )
            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

