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

hub.exec.boto3.client.ec2.copy_fpga_image
hub.exec.boto3.client.ec2.create_fpga_image
hub.exec.boto3.client.ec2.delete_fpga_image
hub.exec.boto3.client.ec2.describe_fpga_images
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, input_storage_location: Dict, name: Text = None, logs_storage_location: Dict = None, description: Text = None, tag_specifications: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates an Amazon FPGA Image (AFI) from the specified design checkpoint (DCP). The create operation is
    asynchronous. To verify that the AFI is ready for use, check the output logs. An AFI contains the FPGA bitstream
    that is ready to download to an FPGA. You can securely deploy an AFI on multiple FPGA-accelerated instances. For
    more information, see the AWS FPGA Hardware Development Kit.

    Args:
        name(Text, optional): A name for the AFI. Defaults to None.
        input_storage_location(Dict): The location of the encrypted design checkpoint in Amazon S3. The input must be a tarball.
        logs_storage_location(Dict, optional): The location in Amazon S3 for the output logs. Defaults to None.
        description(Text, optional): A description for the AFI. Defaults to None.
        tag_specifications(List, optional): The tags to apply to the FPGA image during creation. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.ec2.create_fpga_image(
                ctx,
                DryRun=ctx.test,
                ClientToken=name,
                **{"Name": name, "InputStorageLocation": input_storage_location, "LogsStorageLocation": logs_storage_location, "Description": description, "TagSpecifications": tag_specifications}
            )
            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_fpga_images(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, fpga_image_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified Amazon FPGA Image (AFI).

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

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

