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

hub.exec.boto3.client.detective.create_graph
hub.exec.boto3.client.detective.delete_graph
hub.exec.boto3.client.detective.list_graphs
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, tags: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a new behavior graph for the calling account, and sets that account as the administrator account. This
    operation is called by the account that is enabling Detective. Before you try to enable Detective, make sure
    that your account has been enrolled in Amazon GuardDuty for at least 48 hours. If you do not meet this
    requirement, you cannot enable Detective. If you do meet the GuardDuty prerequisite, then when you make the
    request to enable Detective, it checks whether your data volume is within the Detective quota. If it exceeds the
    quota, then you cannot enable Detective.  The operation also enables Detective for the calling account in the
    currently selected Region. It returns the ARN of the new behavior graph.  CreateGraph triggers a process to
    create the corresponding data tables for the new behavior graph. An account can only be the administrator
    account for one behavior graph within a Region. If the same account calls CreateGraph with the same
    administrator account, it always returns the same behavior graph ARN. It does not create a new behavior graph.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        tags(Dict, optional): The tags to assign to the new behavior graph. You can add up to 50 tags. For each tag, you
            provide the tag key and the tag value. Each tag key can contain up to 128 characters. Each tag
            value can contain up to 256 characters. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

async def absent(hub, ctx, name: Text, graph_arn: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Disables the specified behavior graph and queues it to be deleted. This operation removes the graph from each
    member account's list of behavior graphs.  DeleteGraph can only be called by the administrator account for a
    behavior graph.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        graph_arn(Text): The ARN of the behavior graph to disable.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

