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

hub.exec.boto3.client.elb.create_load_balancer_policy
hub.exec.boto3.client.elb.delete_load_balancer_policy
hub.exec.boto3.client.elb.describe_load_balancer_policies
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, load_balancer_name: Text, policy_name: Text, policy_type_name: Text, policy_attributes: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a policy with the specified attributes for the specified load balancer. Policies are settings that are
    saved for your load balancer and that can be applied to the listener or the application server, depending on the
    policy type.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        load_balancer_name(Text): The name of the load balancer.
        policy_name(Text): The name of the load balancer policy to be created. This name must be unique within the set of
            policies for this load balancer.
        policy_type_name(Text): The name of the base policy type. To get the list of policy types, use
            DescribeLoadBalancerPolicyTypes.
        policy_attributes(List, optional): The policy attributes. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.elb.load_balancer_policy.present:
                - name: value
                - load_balancer_name: value
                - policy_name: value
                - policy_type_name: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.elb.load_balancer_policy.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.elb.describe_load_balancer_policies(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.elb.create_load_balancer_policy(
                ctx,
                
                
                **{"LoadBalancerName": load_balancer_name, "PolicyName": policy_name, "PolicyTypeName": policy_type_name, "PolicyAttributes": policy_attributes}
            )
            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.elb.describe_load_balancer_policies(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, load_balancer_name: Text, policy_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified policy from the specified load balancer. This policy must not be enabled for any
    listeners.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        load_balancer_name(Text): The name of the load balancer.
        policy_name(Text): The name of the policy.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.elb.load_balancer_policy.absent:
                - name: value
                - load_balancer_name: value
                - policy_name: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.elb.load_balancer_policy.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.elb.describe_load_balancer_policies(name)

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.elb.delete_load_balancer_policy(
                ctx,
                
                
                **{"LoadBalancerName": load_balancer_name, "PolicyName": policy_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.elb.describe_load_balancer_policies(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

