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

hub.exec.boto3.client.route53.create_traffic_policy_instance
hub.exec.boto3.client.route53.delete_traffic_policy_instance
hub.exec.boto3.client.route53.get_traffic_policy_instance
hub.exec.boto3.client.route53.list_traffic_policy_instances
hub.exec.boto3.client.route53.update_traffic_policy_instance
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, hosted_zone_id: Text, ttl: int, traffic_policy_id: Text, traffic_policy_version: int)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates resource record sets in a specified hosted zone based on the settings in a specified traffic policy
    version. In addition, CreateTrafficPolicyInstance associates the resource record sets with a specified domain
    name (such as example.com) or subdomain name (such as www.example.com). Amazon Route 53 responds to DNS queries
    for the domain or subdomain name by using the resource record sets that CreateTrafficPolicyInstance created.

    Args:
        name(Text): The domain name (such as example.com) or subdomain name (such as www.example.com) for which
            Amazon Route 53 responds to DNS queries by using the resource record sets that Route 53 creates
            for this traffic policy instance.
        hosted_zone_id(Text): The ID of the hosted zone that you want Amazon Route 53 to create resource record sets in by
            using the configuration in a traffic policy.
        ttl(int): (Optional) The TTL that you want Amazon Route 53 to assign to all of the resource record sets
            that it creates in the specified hosted zone.
        traffic_policy_id(Text): The ID of the traffic policy that you want to use to create resource record sets in the
            specified hosted zone.
        traffic_policy_version(int): The version of the traffic policy that you want to use to create resource record sets in the
            specified hosted zone.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.route53.traffic_policy_instance.present:
                - name: value
                - hosted_zone_id: value
                - ttl: value
                - traffic_policy_id: value
                - traffic_policy_version: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.route53.traffic_policy_instance.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_instance(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.route53.create_traffic_policy_instance(
                ctx,
                
                
                **{"Name": name, "HostedZoneId": hosted_zone_id, "TTL": ttl, "TrafficPolicyId": traffic_policy_id, "TrafficPolicyVersion": traffic_policy_version}
            )
            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_instance(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, id_: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a traffic policy instance and all of the resource record sets that Amazon Route 53 created when you
    created the instance.  In the Route 53 console, traffic policy instances are known as policy records.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        id_(Text): The ID of the traffic policy instance that you want to delete.   When you delete a traffic
            policy instance, Amazon Route 53 also deletes all of the resource record sets that were created
            when you created the traffic policy instance.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

