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

hub.exec.boto3.client.ec2.create_spot_datafeed_subscription
hub.exec.boto3.client.ec2.delete_spot_datafeed_subscription
hub.exec.boto3.client.ec2.describe_spot_datafeed_subscription
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, bucket: Text, prefix: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a data feed for Spot Instances, enabling you to view Spot Instance usage logs. You can create one data
    feed per Amazon Web Services account. For more information, see Spot Instance data feed in the Amazon EC2 User
    Guide for Linux Instances.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        bucket(Text): The name of the Amazon S3 bucket in which to store the Spot Instance data feed. For more
            information about bucket names, see Rules for bucket naming in the Amazon S3 Developer Guide.
        prefix(Text, optional): The prefix for the data feed file names. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.ec2.create_spot_datafeed_subscription(
                ctx,
                DryRun=ctx.test,
                
                **{"Bucket": bucket, "Prefix": prefix}
            )
            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.ec2.describe_spot_datafeed_subscription(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the data feed for Spot Instances.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

