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

hub.exec.boto3.client.accessanalyzer.create_analyzer
hub.exec.boto3.client.accessanalyzer.delete_analyzer
hub.exec.boto3.client.accessanalyzer.get_analyzer
hub.exec.boto3.client.accessanalyzer.list_analyzers
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, analyzer_name: Text, type_: Text, archive_rules: List = None, client_token: Text = None, tags: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates an analyzer for your account.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        analyzer_name(Text): The name of the analyzer to create.
        archive_rules(List, optional): Specifies the archive rules to add for the analyzer. Archive rules automatically archive
            findings that meet the criteria you define for the rule. Defaults to None.
        client_token(Text, optional): A client token. Defaults to None.
        tags(Dict, optional): The tags to apply to the analyzer. Defaults to None.
        type_(Text): The type of analyzer to create. Only ACCOUNT and ORGANIZATION analyzers are supported. You can
            create only one analyzer per account per Region. You can create up to 5 analyzers per
            organization per Region.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.accessanalyzer.create_analyzer(
                ctx,
                
                
                **{"analyzerName": analyzer_name, "archiveRules": archive_rules, "clientToken": client_token, "tags": tags, "type": type_}
            )
            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_analyzer(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, analyzer_name: Text, client_token: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified analyzer. When you delete an analyzer, Access Analyzer is disabled for the account or
    organization in the current or specific Region. All findings that were generated by the analyzer are deleted.
    You cannot undo this action.

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

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

