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

hub.exec.boto3.client.ec2.create_subnet_cidr_reservation
hub.exec.boto3.client.ec2.delete_subnet_cidr_reservation
hub.exec.boto3.client.ec2.get_subnet_cidr_reservations
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, subnet_id: Text, cidr: Text, reservation_type: Text, tag_specifications: List = None, description: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a subnet CIDR reservation. For information about subnet CIDR reservations, see Subnet CIDR reservations
    in the Amazon Virtual Private Cloud User Guide.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        tag_specifications(List, optional): The tags to assign to the subnet CIDR reservation. Defaults to None.
        subnet_id(Text): The ID of the subnet.
        cidr(Text): The IPv4 or IPV6 CIDR range to reserve.
        reservation_type(Text): The type of reservation. The following are valid values:    prefix: The Amazon EC2 Prefix
            Delegation feature assigns the IP addresses to network interfaces that are associated with an
            instance. For information about Prefix Delegation, see Prefix Delegation for Amazon EC2 network
            interfaces in the Amazon Elastic Compute Cloud User Guide.    explicit: You manually assign the
            IP addresses to resources that reside in your subnet.
        description(Text, optional): The description to assign to the subnet CIDR reservation. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.ec2.create_subnet_cidr_reservation(
                ctx,
                DryRun=ctx.test,
                
                **{"TagSpecifications": tag_specifications, "SubnetId": subnet_id, "Cidr": cidr, "ReservationType": reservation_type, "Description": description}
            )
            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.get_subnet_cidr_reservations(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, subnet_cidr_reservation_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a subnet CIDR reservation.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        subnet_cidr_reservation_id(Text): The ID of the subnet CIDR reservation.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

