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

hub.exec.boto3.client.route53.create_traffic_policy
hub.exec.boto3.client.route53.delete_traffic_policy
hub.exec.boto3.client.route53.get_traffic_policy
hub.exec.boto3.client.route53.list_traffic_policies
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, document: Text, comment: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a traffic policy, which you use to create multiple DNS resource record sets for one domain name (such as
    example.com) or one subdomain name (such as www.example.com).

    Args:
        name(Text): The name of the traffic policy.
        document(Text): The definition of this traffic policy in JSON format. For more information, see Traffic Policy
            Document Format.
        comment(Text, optional): (Optional) Any comments that you want to include about the traffic policy. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.route53.traffic_policy.present:
                - name: value
                - document: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.route53.traffic_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.route53.get_traffic_policy(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.route53.create_traffic_policy(
                ctx,
                
                
                **{"Name": name, "Document": document, "Comment": comment}
            )
            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.route53.get_traffic_policy(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, id_: Text, version: int)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a traffic policy. When you delete a traffic policy, Route 53 sets a flag on the policy to indicate that
    it has been deleted. However, Route 53 never fully deletes the traffic policy. Note the following:   Deleted
    traffic policies aren't listed if you run ListTrafficPolicies.    There's no way to get a list of deleted
    policies.   If you retain the ID of the policy, you can get information about the policy, including the traffic
    policy document, by running GetTrafficPolicy.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        id_(Text): The ID of the traffic policy that you want to delete.
        version(int): The version number of the traffic policy that you want to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.route53.traffic_policy.absent:
                - name: value
                - id_: value
                - version: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.route53.traffic_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.route53.get_traffic_policy(name)

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.route53.delete_traffic_policy(
                ctx,
                
                
                **{"Id": id_, "Version": version}
            )
            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.route53.get_traffic_policy(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

