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

hub.exec.boto3.client.ec2.allocate_hosts
hub.exec.boto3.client.ec2.describe_hosts
hub.exec.boto3.client.ec2.modify_hosts
hub.exec.boto3.client.ec2.release_hosts
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, availability_zone: Text, quantity: int, auto_placement: Text = None, instance_type: Text = None, instance_family: Text = None, tag_specifications: List = None, host_recovery: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Allocates a Dedicated Host to your account. At a minimum, specify the supported instance type or instance
    family, the Availability Zone in which to allocate the host, and the number of hosts to allocate.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        auto_placement(Text, optional): Indicates whether the host accepts any untargeted instance launches that match its instance type
            configuration, or if it only accepts Host tenancy instance launches that specify its unique host
            ID. For more information, see  Understanding auto-placement and affinity in the Amazon EC2 User
            Guide. Default: on. Defaults to None.
        availability_zone(Text): The Availability Zone in which to allocate the Dedicated Host.
        instance_type(Text, optional): Specifies the instance type to be supported by the Dedicated Hosts. If you specify an instance
            type, the Dedicated Hosts support instances of the specified instance type only. If you want the
            Dedicated Hosts to support multiple instance types in a specific instance family, omit this
            parameter and specify InstanceFamily instead. You cannot specify InstanceType and InstanceFamily
            in the same request. Defaults to None.
        instance_family(Text, optional): Specifies the instance family to be supported by the Dedicated Hosts. If you specify an instance
            family, the Dedicated Hosts support multiple instance types within that instance family. If you
            want the Dedicated Hosts to support a specific instance type only, omit this parameter and
            specify InstanceType instead. You cannot specify InstanceFamily and InstanceType in the same
            request. Defaults to None.
        quantity(int): The number of Dedicated Hosts to allocate to your account with these parameters.
        tag_specifications(List, optional): The tags to apply to the Dedicated Host during creation. Defaults to None.
        host_recovery(Text, optional): Indicates whether to enable or disable host recovery for the Dedicated Host. Host recovery is
            disabled by default. For more information, see  Host recovery in the Amazon EC2 User Guide.
            Default: off. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.ec2.allocate_hosts(
                ctx,
                
                ClientToken=name,
                **{"AutoPlacement": auto_placement, "AvailabilityZone": availability_zone, "InstanceType": instance_type, "InstanceFamily": instance_family, "Quantity": quantity, "TagSpecifications": tag_specifications, "HostRecovery": host_recovery}
            )
            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_hosts(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, host_ids: List)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    When you no longer want to use an On-Demand Dedicated Host it can be released. On-Demand billing is stopped and
    the host goes into released state. The host ID of Dedicated Hosts that have been released can no longer be
    specified in another request, for example, to modify the host. You must stop or terminate all instances on a
    host before it can be released. When Dedicated Hosts are released, it may take some time for them to stop
    counting toward your limit and you may receive capacity errors when trying to allocate new Dedicated Hosts. Wait
    a few minutes and then try again. Released hosts still appear in a DescribeHosts response.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        host_ids(List): The IDs of the Dedicated Hosts to release.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

