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

hub.exec.boto3.client.config.delete_config_rule
hub.exec.boto3.client.config.describe_config_rules
hub.exec.boto3.client.config.put_config_rule
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, config_rule: Dict, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Adds or updates an AWS Config rule for evaluating whether your AWS resources comply with your desired
    configurations. You can use this action for custom AWS Config rules and AWS managed Config rules. A custom AWS
    Config rule is a rule that you develop and maintain. An AWS managed Config rule is a customizable, predefined
    rule that AWS Config provides. If you are adding a new custom AWS Config rule, you must first create the AWS
    Lambda function that the rule invokes to evaluate your resources. When you use the PutConfigRule action to add
    the rule to AWS Config, you must specify the Amazon Resource Name (ARN) that AWS Lambda assigns to the function.
    Specify the ARN for the SourceIdentifier key. This key is part of the Source object, which is part of the
    ConfigRule object.  If you are adding an AWS managed Config rule, specify the rule's identifier for the
    SourceIdentifier key. To reference AWS managed Config rule identifiers, see About AWS Managed Config Rules. For
    any new rule that you add, specify the ConfigRuleName in the ConfigRule object. Do not specify the ConfigRuleArn
    or the ConfigRuleId. These values are generated by AWS Config for new rules. If you are updating a rule that you
    added previously, you can specify the rule by ConfigRuleName, ConfigRuleId, or ConfigRuleArn in the ConfigRule
    data type that you use in this request. The maximum number of rules that AWS Config supports is 150. For
    information about requesting a rule limit increase, see AWS Config Limits in the AWS General Reference Guide.
    For more information about developing and using AWS Config rules, see Evaluating AWS Resource Configurations
    with AWS Config in the AWS Config Developer Guide.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        config_rule(Dict): The rule that you want to add to your account.
        tags(List, optional): An array of tag object. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

async def absent(hub, ctx, name: Text, config_rule_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified AWS Config rule and all of its evaluation results. AWS Config sets the state of a rule to
    DELETING until the deletion is complete. You cannot update a rule while it is in this state. If you make a
    PutConfigRule or DeleteConfigRule request for the rule, you will receive a ResourceInUseException. You can check
    the state of a rule by using the DescribeConfigRules request.

    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 that you want to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

