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

hub.exec.boto3.client.lightsail.create_instances
hub.exec.boto3.client.lightsail.delete_instance
hub.exec.boto3.client.lightsail.get_instances
hub.exec.boto3.client.lightsail.reboot_instance
hub.exec.boto3.client.lightsail.start_instance
hub.exec.boto3.client.lightsail.stop_instance
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, instance_names: List, availability_zone: Text, blueprint_id: Text, bundle_id: Text, custom_image_name: Text = None, user_data: Text = None, key_pair_name: Text = None, tags: List = None, add_ons: List = None, ip_address_type: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates one or more Amazon Lightsail instances. The create instances operation supports tag-based access control
    via request tags. For more information, see the Lightsail Developer Guide.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        instance_names(List): The names to use for your new Lightsail instances. Separate multiple values using quotation
            marks and commas, for example: ["MyFirstInstance","MySecondInstance"].
        availability_zone(Text): The Availability Zone in which to create your instance. Use the following format: us-east-2a
            (case sensitive). You can get a list of Availability Zones by using the get regions operation.
            Be sure to add the include Availability Zones parameter to your request.
        custom_image_name(Text, optional): (Deprecated) The name for your custom image.  In releases prior to June 12, 2017, this parameter
            was ignored by the API. It is now deprecated. Defaults to None.
        blueprint_id(Text): The ID for a virtual private server image (e.g., app_wordpress_4_4 or app_lamp_7_0). Use the get
            blueprints operation to return a list of available images (or blueprints).  Use active
            blueprints when creating new instances. Inactive blueprints are listed to support customers with
            existing instances and are not necessarily available to create new instances. Blueprints are
            marked inactive when they become outdated due to operating system updates or new application
            releases.
        bundle_id(Text): The bundle of specification information for your virtual private server (or instance), including
            the pricing plan (e.g., micro_1_0).
        user_data(Text, optional): A launch script you can create that configures a server with additional user data. For example,
            you might want to run apt-get -y update.  Depending on the machine image you choose, the command
            to get software on your instance varies. Amazon Linux and CentOS use yum, Debian and Ubuntu use
            apt-get, and FreeBSD uses pkg. For a complete list, see the Amazon Lightsail Developer Guide. Defaults to None.
        key_pair_name(Text, optional): The name of your key pair. 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.
        add_ons(List, optional): An array of objects representing the add-ons to enable for the new instance. Defaults to None.
        ip_address_type(Text, optional): The IP address type for the instance. The possible values are ipv4 for IPv4 only, and dualstack
            for IPv4 and IPv6. The default value is dualstack. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.lightsail.instance.present:
                - name: value
                - instance_names: value
                - availability_zone: value
                - blueprint_id: value
                - bundle_id: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.lightsail.instance.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_instances(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.lightsail.create_instances(
                ctx,
                
                
                **{"instanceNames": instance_names, "availabilityZone": availability_zone, "customImageName": custom_image_name, "blueprintId": blueprint_id, "bundleId": bundle_id, "userData": user_data, "keyPairName": key_pair_name, "tags": tags, "addOns": add_ons, "ipAddressType": ip_address_type}
            )
            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_instances(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, instance_name: Text, force_delete_add_ons: bool = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes an Amazon Lightsail instance. The delete instance operation supports tag-based access control via
    resource tags applied to the resource identified by instance 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_name(Text): The name of the instance to delete.
        force_delete_add_ons(bool, optional): A Boolean value to indicate whether to delete the enabled add-ons for the disk. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

