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

hub.exec.boto3.client.route53.create_reusable_delegation_set
hub.exec.boto3.client.route53.delete_reusable_delegation_set
hub.exec.boto3.client.route53.get_reusable_delegation_set
hub.exec.boto3.client.route53.list_reusable_delegation_sets
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, caller_reference: Text, hosted_zone_id: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a delegation set (a group of four name servers) that can be reused by multiple hosted zones that were
    created by the same Amazon Web Services account.  You can also create a reusable delegation set that uses the
    four name servers that are associated with an existing hosted zone. Specify the hosted zone ID in the
    CreateReusableDelegationSet request.  You can't associate a reusable delegation set with a private hosted zone.
    For information about using a reusable delegation set to configure white label name servers, see Configuring
    White Label Name Servers. The process for migrating existing hosted zones to use a reusable delegation set is
    comparable to the process for configuring white label name servers. You need to perform the following steps:
    Create a reusable delegation set.   Recreate hosted zones, and reduce the TTL to 60 seconds or less.   Recreate
    resource record sets in the new hosted zones.   Change the registrar's name servers to use the name servers for
    the new hosted zones.   Monitor traffic for the website or application.   Change TTLs back to their original
    values.   If you want to migrate existing hosted zones to use a reusable delegation set, the existing hosted
    zones can't use any of the name servers that are assigned to the reusable delegation set. If one or more hosted
    zones do use one or more name servers that are assigned to the reusable delegation set, you can do one of the
    following:   For small numbers of hosted zones—up to a few hundred—it's relatively easy to create reusable
    delegation sets until you get one that has four name servers that don't overlap with any of the name servers in
    your hosted zones.   For larger numbers of hosted zones, the easiest solution is to use more than one reusable
    delegation set.   For larger numbers of hosted zones, you can also migrate hosted zones that have overlapping
    name servers to hosted zones that don't have overlapping name servers, then migrate the hosted zones again to
    use the reusable delegation set.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        caller_reference(Text): A unique string that identifies the request, and that allows you to retry failed
            CreateReusableDelegationSet requests without the risk of executing the operation twice. You must
            use a unique CallerReference string every time you submit a CreateReusableDelegationSet request.
            CallerReference can be any unique string, for example a date/time stamp.
        hosted_zone_id(Text, optional): If you want to mark the delegation set for an existing hosted zone as reusable, the ID for that
            hosted zone. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.route53.create_reusable_delegation_set(
                ctx,
                
                
                **{"CallerReference": caller_reference, "HostedZoneId": hosted_zone_id}
            )
            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_reusable_delegation_set(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 reusable delegation set.  You can delete a reusable delegation set only if it isn't associated with
    any hosted zones.  To verify that the reusable delegation set is not associated with any hosted zones, submit a
    GetReusableDelegationSet request and specify the ID of the reusable delegation set that you want to delete.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        id_(Text): The ID of the reusable delegation set that you want to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

