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

hub.exec.boto3.client.elbv2.create_rule
hub.exec.boto3.client.elbv2.delete_rule
hub.exec.boto3.client.elbv2.describe_rules
hub.exec.boto3.client.elbv2.modify_rule
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, listener_arn: Text, conditions: List, priority: int, actions: List, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a rule for the specified listener. The listener must be associated with an Application Load Balancer.
    Each rule consists of a priority, one or more actions, and one or more conditions. Rules are evaluated in
    priority order, from the lowest value to the highest value. When the conditions for a rule are met, its actions
    are performed. If the conditions for no rules are met, the actions for the default rule are performed. For more
    information, see Listener rules in the Application Load Balancers Guide.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        listener_arn(Text): The Amazon Resource Name (ARN) of the listener.
        conditions(List): The conditions.
        priority(int): The rule priority. A listener can't have multiple rules with the same priority.
        actions(List): The actions.
        tags(List, optional): The tags to assign to the rule. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.elbv2.rule.present:
                - name: value
                - listener_arn: value
                - conditions: value
                - priority: value
                - actions: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.elbv2.rule.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.elbv2.describe_rules(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.elbv2.create_rule(
                ctx,
                
                
                **{"ListenerArn": listener_arn, "Conditions": conditions, "Priority": priority, "Actions": actions, "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.elbv2.describe_rules(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, rule_arn: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified rule. You can't delete the default rule.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        rule_arn(Text): The Amazon Resource Name (ARN) of the rule.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

