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

hub.exec.boto3.client.budgets.create_budget
hub.exec.boto3.client.budgets.delete_budget
hub.exec.boto3.client.budgets.describe_budgets
hub.exec.boto3.client.budgets.update_budget
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, account_id: Text, budget: Dict, notifications_with_subscribers: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a budget and, if included, notifications and subscribers.   Only one of BudgetLimit or
    PlannedBudgetLimits can be present in the syntax at one time. Use the syntax that matches your case. The Request
    Syntax section shows the BudgetLimit syntax. For PlannedBudgetLimits, see the Examples section.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        account_id(Text): The accountId that is associated with the budget.
        budget(Dict): The budget object that you want to create.
        notifications_with_subscribers(List, optional): A notification that you want to associate with a budget. A budget can have up to five
            notifications, and each notification can have one SNS subscriber and up to 10 email subscribers.
            If you include notifications and subscribers in your CreateBudget call, AWS creates the
            notifications and subscribers for you. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.budgets.create_budget(
                ctx,
                
                
                **{"AccountId": account_id, "Budget": budget, "NotificationsWithSubscribers": notifications_with_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_budgets(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, account_id: Text, budget_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a budget. You can delete your budget at any time.  Deleting a budget also deletes the notifications and
    subscribers that are associated with that budget.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        account_id(Text): The accountId that is associated with the budget that you want to delete.
        budget_name(Text): The name of the budget that you want to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

