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

hub.exec.boto3.client.ds.create_conditional_forwarder
hub.exec.boto3.client.ds.delete_conditional_forwarder
hub.exec.boto3.client.ds.describe_conditional_forwarders
hub.exec.boto3.client.ds.update_conditional_forwarder
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, directory_id: Text, remote_domain_name: Text, dns_ip_addrs: List)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a conditional forwarder associated with your Amazon Web Services directory. Conditional forwarders are
    required in order to set up a trust relationship with another domain. The conditional forwarder points to the
    trusted domain.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        directory_id(Text): The directory ID of the Amazon Web Services directory for which you are creating the conditional
            forwarder.
        remote_domain_name(Text): The fully qualified domain name (FQDN) of the remote domain with which you will set up a trust
            relationship.
        dns_ip_addrs(List): The IP addresses of the remote DNS server associated with RemoteDomainName.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.ds.conditional_forwarder.present:
                - name: value
                - directory_id: value
                - remote_domain_name: value
                - dns_ip_addrs: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.ds.conditional_forwarder.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.ds.describe_conditional_forwarders(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.ds.create_conditional_forwarder(
                ctx,
                
                
                **{"DirectoryId": directory_id, "RemoteDomainName": remote_domain_name, "DnsIpAddrs": dns_ip_addrs}
            )
            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.ds.describe_conditional_forwarders(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, directory_id: Text, remote_domain_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a conditional forwarder that has been set up for your Amazon Web Services directory.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        directory_id(Text): The directory ID for which you are deleting the conditional forwarder.
        remote_domain_name(Text): The fully qualified domain name (FQDN) of the remote domain with which you are deleting the
            conditional forwarder.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.ds.conditional_forwarder.absent:
                - name: value
                - directory_id: value
                - remote_domain_name: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.ds.conditional_forwarder.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.ds.describe_conditional_forwarders(name)

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.ds.delete_conditional_forwarder(
                ctx,
                
                
                **{"DirectoryId": directory_id, "RemoteDomainName": remote_domain_name}
            )
            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.ds.describe_conditional_forwarders(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

