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

hub.exec.boto3.client.config.delete_remediation_exceptions
hub.exec.boto3.client.config.describe_remediation_exceptions
hub.exec.boto3.client.config.put_remediation_exceptions
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, config_rule_name: Text, resource_keys: List, message: Text = None, expiration_time: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    A remediation exception is when a specific resource is no longer considered for auto-remediation. This API adds
    a new exception or updates an existing exception for a specific resource with a specific AWS Config rule.   AWS
    Config generates a remediation exception when a problem occurs executing a remediation action to a specific
    resource. Remediation exceptions blocks auto-remediation until the exception is cleared.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        config_rule_name(Text): The name of the AWS Config rule for which you want to create remediation exception.
        resource_keys(List): An exception list of resource exception keys to be processed with the current request. AWS
            Config adds exception for each resource key. For example, AWS Config adds 3 exceptions for 3
            resource keys.
        message(Text, optional): The message contains an explanation of the exception. Defaults to None.
        expiration_time(Text, optional): The exception is automatically deleted after the expiration date. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.config.remediation_exception.present:
                - name: value
                - config_rule_name: value
                - resource_keys: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.config.remediation_exception.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.config.describe_remediation_exceptions(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.config.put_remediation_exceptions(
                ctx,
                
                
                **{"ConfigRuleName": config_rule_name, "ResourceKeys": resource_keys, "Message": message, "ExpirationTime": expiration_time}
            )
            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.config.describe_remediation_exceptions(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, config_rule_name: Text, resource_keys: List)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes one or more remediation exceptions mentioned in the resource keys.  AWS Config generates a remediation
    exception when a problem occurs executing a remediation action to a specific resource. Remediation exceptions
    blocks auto-remediation until the exception is cleared.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        config_rule_name(Text): The name of the AWS Config rule for which you want to delete remediation exception
            configuration.
        resource_keys(List): An exception list of resource exception keys to be processed with the current request. AWS
            Config adds exception for each resource key. For example, AWS Config adds 3 exceptions for 3
            resource keys.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.config.remediation_exception.absent:
                - name: value
                - config_rule_name: value
                - resource_keys: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.config.remediation_exception.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.config.describe_remediation_exceptions(name)

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.config.delete_remediation_exceptions(
                ctx,
                
                
                **{"ConfigRuleName": config_rule_name, "ResourceKeys": resource_keys}
            )
            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.config.describe_remediation_exceptions(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

