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

hub.exec.boto3.client.config.delete_remediation_configuration
hub.exec.boto3.client.config.describe_remediation_configurations
hub.exec.boto3.client.config.put_remediation_configurations
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, remediation_configurations: List)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Adds or updates the remediation configuration with a specific AWS Config rule with the selected target or
    action. The API creates the RemediationConfiguration object for the AWS Config rule. The AWS Config rule must
    already exist for you to add a remediation configuration. The target (SSM document) must exist and have
    permissions to use the target.   If you make backward incompatible changes to the SSM document, you must call
    this again to ensure the remediations can run. This API does not support adding remediation configurations for
    service-linked AWS Config Rules such as Organization Config rules, the rules deployed by conformance packs, and
    rules deployed by AWS Security Hub.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        remediation_configurations(List): A list of remediation configuration objects.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.config.put_remediation_configurations(
                ctx,
                
                
                **{"RemediationConfigurations": remediation_configurations}
            )
            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_configurations(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, config_rule_name: Text, resource_type: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the remediation configuration.

    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 configuration.
        resource_type(Text, optional): The type of a resource. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

