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

hub.exec.boto3.client.iot.create_mitigation_action
hub.exec.boto3.client.iot.delete_mitigation_action
hub.exec.boto3.client.iot.describe_mitigation_action
hub.exec.boto3.client.iot.list_mitigation_actions
hub.exec.boto3.client.iot.update_mitigation_action
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, action_name: Text, role_arn: Text, action_params: Dict, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Defines an action that can be applied to audit findings by using StartAuditMitigationActionsTask. Only certain
    types of mitigation actions can be applied to specific check names. For more information, see Mitigation
    actions. Each mitigation action can apply only one type of change.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        action_name(Text): A friendly name for the action. Choose a friendly name that accurately describes the action (for
            example, EnableLoggingAction).
        role_arn(Text): The ARN of the IAM role that is used to apply the mitigation action.
        action_params(Dict): Defines the type of action and the parameters for that action.
        tags(List, optional): Metadata that can be used to manage the mitigation action. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.iot.mitigation_action.present:
                - name: value
                - action_name: value
                - role_arn: value
                - action_params: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.iot.mitigation_action.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.iot.describe_mitigation_action(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.iot.create_mitigation_action(
                ctx,
                
                
                **{"actionName": action_name, "roleArn": role_arn, "actionParams": action_params, "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.iot.describe_mitigation_action(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, action_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a defined mitigation action from your AWS account.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        action_name(Text): The name of the mitigation action that you want to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

