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

hub.exec.boto3.client.ds.deregister_certificate
hub.exec.boto3.client.ds.describe_certificate
hub.exec.boto3.client.ds.list_certificates
hub.exec.boto3.client.ds.register_certificate
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, directory_id: Text, certificate_data: Text, type_: Text = None, client_cert_auth_settings: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Registers a certificate for a secure LDAP or client certificate authentication.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        directory_id(Text): The identifier of the directory.
        certificate_data(Text): The certificate PEM string that needs to be registered.
        type_(Text, optional): The function that the registered certificate performs. Valid values include ClientLDAPS or
            ClientCertAuth. The default value is ClientLDAPS. Defaults to None.
        client_cert_auth_settings(Dict, optional): A ClientCertAuthSettings object that contains client certificate authentication settings. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.ds.register_certificate(
                ctx,
                
                
                **{"DirectoryId": directory_id, "CertificateData": certificate_data, "Type": type_, "ClientCertAuthSettings": client_cert_auth_settings}
            )
            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_certificate(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, directory_id: Text, certificate_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes from the system the certificate that was registered for secure LDAP or client certificate
    authentication.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        directory_id(Text): The identifier of the directory.
        certificate_id(Text): The identifier of the certificate.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

