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

hub.exec.boto3.client.accessanalyzer.apply_archive_rule
hub.exec.boto3.client.accessanalyzer.create_archive_rule
hub.exec.boto3.client.accessanalyzer.delete_archive_rule
hub.exec.boto3.client.accessanalyzer.get_archive_rule
hub.exec.boto3.client.accessanalyzer.list_archive_rules
hub.exec.boto3.client.accessanalyzer.update_archive_rule
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, analyzer_name: Text, filter_: Dict, rule_name: Text, client_token: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates an archive rule for the specified analyzer. Archive rules automatically archive new findings that meet
    the criteria you define when you create the rule. To learn about filter keys that you can use to create an
    archive rule, see Access Analyzer filter keys in the IAM User Guide.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        analyzer_name(Text): The name of the created analyzer.
        client_token(Text, optional): A client token. Defaults to None.
        filter_(Dict): The criteria for the rule.
        rule_name(Text): The name of the rule to create.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.accessanalyzer.archive_rule.present:
                - name: value
                - analyzer_name: value
                - filter_: value
                - rule_name: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.accessanalyzer.archive_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.accessanalyzer.get_archive_rule(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.accessanalyzer.create_archive_rule(
                ctx,
                
                
                **{"analyzerName": analyzer_name, "clientToken": client_token, "filter": filter_, "ruleName": rule_name}
            )
            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.accessanalyzer.get_archive_rule(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, analyzer_name: Text, rule_name: Text, client_token: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified archive rule.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        analyzer_name(Text): The name of the analyzer that associated with the archive rule to delete.
        client_token(Text, optional): A client token. Defaults to None.
        rule_name(Text): The name of the rule to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.accessanalyzer.archive_rule.absent:
                - name: value
                - analyzer_name: value
                - rule_name: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.accessanalyzer.archive_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.accessanalyzer.get_archive_rule(name)

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.accessanalyzer.delete_archive_rule(
                ctx,
                
                
                **{"analyzerName": analyzer_name, "clientToken": client_token, "ruleName": 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.accessanalyzer.get_archive_rule(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

