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

hub.exec.boto3.client.budgets.create_budget_action
hub.exec.boto3.client.budgets.delete_budget_action
hub.exec.boto3.client.budgets.describe_budget_action
hub.exec.boto3.client.budgets.execute_budget_action
hub.exec.boto3.client.budgets.update_budget_action
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, account_id: Text, budget_name: Text, notification_type: Text, action_type: Text, action_threshold: Dict, definition: Dict, execution_role_arn: Text, approval_model: Text, subscribers: List)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
     Creates a budget action.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        account_id(Text): The account ID of the user. It should be a 12-digit number.
        budget_name(Text):  A string that represents the budget name. The ":" and "\" characters aren't allowed.
        notification_type(Text):  The type of a notification. It must be ACTUAL or FORECASTED.
        action_type(Text):  The type of action. This defines the type of tasks that can be carried out by this action. This
            field also determines the format for definition.
        action_threshold(Dict):  The trigger threshold of the action.
        definition(Dict):  Specifies all of the type-specific parameters.
        execution_role_arn(Text):  The role passed for action execution and reversion. Roles and actions must be in the same
            account.
        approval_model(Text):  This specifies if the action needs manual or automatic approval.
        subscribers(List):  A list of subscribers.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.budgets.budget_action.present:
                - name: value
                - account_id: value
                - budget_name: value
                - notification_type: value
                - action_type: value
                - action_threshold: value
                - definition: value
                - execution_role_arn: value
                - approval_model: value
                - subscribers: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.budgets.budget_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.budgets.describe_budget_action(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.budgets.create_budget_action(
                ctx,
                
                
                **{"AccountId": account_id, "BudgetName": budget_name, "NotificationType": notification_type, "ActionType": action_type, "ActionThreshold": action_threshold, "Definition": definition, "ExecutionRoleArn": execution_role_arn, "ApprovalModel": approval_model, "Subscribers": subscribers}
            )
            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.budgets.describe_budget_action(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, account_id: Text, budget_name: Text, action_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
     Deletes a budget action.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        account_id(Text): The account ID of the user. It should be a 12-digit number.
        budget_name(Text):  A string that represents the budget name. The ":" and "\" characters aren't allowed.
        action_id(Text):  A system-generated universally unique identifier (UUID) for the action.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.budgets.budget_action.absent:
                - name: value
                - account_id: value
                - budget_name: value
                - action_id: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.budgets.budget_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.budgets.describe_budget_action(name)

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.budgets.delete_budget_action(
                ctx,
                
                
                **{"AccountId": account_id, "BudgetName": budget_name, "ActionId": action_id}
            )
            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.budgets.describe_budget_action(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

