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

hub.exec.boto3.client.ce.create_cost_category_definition
hub.exec.boto3.client.ce.delete_cost_category_definition
hub.exec.boto3.client.ce.describe_cost_category_definition
hub.exec.boto3.client.ce.list_cost_category_definitions
hub.exec.boto3.client.ce.update_cost_category_definition
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, rule_version: Text, rules: List, default_value: Text = None, split_charge_rules: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a new Cost Category with the requested name and rules.

    Args:
        name(Text): The unique name of the Cost Category.
        rule_version(Text): The rule schema version in this particular Cost Category.
        rules(List): The Cost Category rules used to categorize costs. For more information, see CostCategoryRule.
        default_value(Text, optional): The default value for the cost category. Defaults to None.
        split_charge_rules(List, optional):  The split charge rules used to allocate your charges between your Cost Category values. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.ce.create_cost_category_definition(
                ctx,
                
                
                **{"Name": name, "RuleVersion": rule_version, "Rules": rules, "DefaultValue": default_value, "SplitChargeRules": split_charge_rules}
            )
            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.ce.describe_cost_category_definition(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, cost_category_arn: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a Cost Category. Expenses from this month going forward will no longer be categorized with this Cost
    Category.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        cost_category_arn(Text):  The unique identifier for your Cost Category.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

