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

hub.exec.boto3.client.ds.create_trust
hub.exec.boto3.client.ds.delete_trust
hub.exec.boto3.client.ds.describe_trusts
hub.exec.boto3.client.ds.update_trust
hub.exec.boto3.client.ds.verify_trust
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, directory_id: Text, remote_domain_name: Text, trust_password: Text, trust_direction: Text, trust_type: Text = None, conditional_forwarder_ip_addrs: List = None, selective_auth: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Directory Service for Microsoft Active Directory allows you to configure trust relationships. For example, you
    can establish a trust between your Managed Microsoft AD directory, and your existing self-managed Microsoft
    Active Directory. This would allow you to provide users and groups access to resources in either domain, with a
    single set of credentials. This action initiates the creation of the Amazon Web Services side of a trust
    relationship between an Managed Microsoft AD directory and an external domain. You can create either a forest
    trust or an external trust.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        directory_id(Text): The Directory ID of the Managed Microsoft AD directory for which to establish the trust
            relationship.
        remote_domain_name(Text): The Fully Qualified Domain Name (FQDN) of the external domain for which to create the trust
            relationship.
        trust_password(Text): The trust password. The must be the same password that was used when creating the trust
            relationship on the external domain.
        trust_direction(Text): The direction of the trust relationship.
        trust_type(Text, optional): The trust relationship type. Forest is the default. Defaults to None.
        conditional_forwarder_ip_addrs(List, optional): The IP addresses of the remote DNS server associated with RemoteDomainName. Defaults to None.
        selective_auth(Text, optional): Optional parameter to enable selective authentication for the trust. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.ds.create_trust(
                ctx,
                
                
                **{"DirectoryId": directory_id, "RemoteDomainName": remote_domain_name, "TrustPassword": trust_password, "TrustDirection": trust_direction, "TrustType": trust_type, "ConditionalForwarderIpAddrs": conditional_forwarder_ip_addrs, "SelectiveAuth": selective_auth}
            )
            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_trusts(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, trust_id: Text, delete_associated_conditional_forwarder: bool = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes an existing trust relationship between your Managed Microsoft AD directory and an external domain.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        trust_id(Text): The Trust ID of the trust relationship to be deleted.
        delete_associated_conditional_forwarder(bool, optional): Delete a conditional forwarder as part of a DeleteTrustRequest. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.ds.delete_trust(
                ctx,
                
                
                **{"TrustId": trust_id, "DeleteAssociatedConditionalForwarder": delete_associated_conditional_forwarder}
            )
            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_trusts(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

