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

hub.exec.boto3.client.route53resolver.associate_resolver_endpoint_ip_address
hub.exec.boto3.client.route53resolver.disassociate_resolver_endpoint_ip_address
hub.exec.boto3.client.route53resolver.list_resolver_endpoint_ip_addresses
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, resolver_endpoint_id: Text, ip_address: Dict)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Adds IP addresses to an inbound or an outbound Resolver endpoint. If you want to add more than one IP address,
    submit one AssociateResolverEndpointIpAddress request for each IP address. To remove an IP address from an
    endpoint, see DisassociateResolverEndpointIpAddress.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        resolver_endpoint_id(Text): The ID of the Resolver endpoint that you want to associate IP addresses with.
        ip_address(Dict): Either the IPv4 address that you want to add to a Resolver endpoint or a subnet ID. If you
            specify a subnet ID, Resolver chooses an IP address for you from the available IPs in the
            specified subnet.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.route53resolver.resolver_endpoint_ip_address.present:
                - name: value
                - resolver_endpoint_id: value
                - ip_address: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.route53resolver.resolver_endpoint_ip_address.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.route53resolver.list_resolver_endpoint_ip_addresses(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.route53resolver.associate_resolver_endpoint_ip_address(
                ctx,
                
                
                **{"ResolverEndpointId": resolver_endpoint_id, "IpAddress": ip_address}
            )
            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.route53resolver.list_resolver_endpoint_ip_addresses(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, resolver_endpoint_id: Text, ip_address: Dict)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Removes IP addresses from an inbound or an outbound Resolver endpoint. If you want to remove more than one IP
    address, submit one DisassociateResolverEndpointIpAddress request for each IP address. To add an IP address to
    an endpoint, see AssociateResolverEndpointIpAddress.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        resolver_endpoint_id(Text): The ID of the Resolver endpoint that you want to disassociate an IP address from.
        ip_address(Dict): The IPv4 address that you want to remove from a Resolver endpoint.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.route53resolver.disassociate_resolver_endpoint_ip_address(
                ctx,
                
                
                **{"ResolverEndpointId": resolver_endpoint_id, "IpAddress": ip_address}
            )
            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.route53resolver.list_resolver_endpoint_ip_addresses(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

