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

hub.exec.boto3.client.route53.create_vpc_association_authorization
hub.exec.boto3.client.route53.delete_vpc_association_authorization
hub.exec.boto3.client.route53.list_vpc_association_authorizations
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, hosted_zone_id: Text, vpc: Dict)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Authorizes the Amazon Web Services account that created a specified VPC to submit an AssociateVPCWithHostedZone
    request to associate the VPC with a specified hosted zone that was created by a different account. To submit a
    CreateVPCAssociationAuthorization request, you must use the account that created the hosted zone. After you
    authorize the association, use the account that created the VPC to submit an AssociateVPCWithHostedZone request.
    If you want to associate multiple VPCs that you created by using one account with a hosted zone that you created
    by using a different account, you must submit one authorization request for each VPC.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        hosted_zone_id(Text): The ID of the private hosted zone that you want to authorize associating a VPC with.
        vpc(Dict): A complex type that contains the VPC ID and region for the VPC that you want to authorize
            associating with your hosted zone.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.route53.create_vpc_association_authorization(
                ctx,
                
                
                **{"HostedZoneId": hosted_zone_id, "VPC": vpc}
            )
            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.list_vpc_association_authorizations(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, hosted_zone_id: Text, vpc: Dict)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Removes authorization to submit an AssociateVPCWithHostedZone request to associate a specified VPC with a hosted
    zone that was created by a different account. You must use the account that created the hosted zone to submit a
    DeleteVPCAssociationAuthorization request.  Sending this request only prevents the Amazon Web Services account
    that created the VPC from associating the VPC with the Amazon Route 53 hosted zone in the future. If the VPC is
    already associated with the hosted zone, DeleteVPCAssociationAuthorization won't disassociate the VPC from the
    hosted zone. If you want to delete an existing association, use DisassociateVPCFromHostedZone.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        hosted_zone_id(Text): When removing authorization to associate a VPC that was created by one Amazon Web Services
            account with a hosted zone that was created with a different Amazon Web Services account, the ID
            of the hosted zone.
        vpc(Dict): When removing authorization to associate a VPC that was created by one Amazon Web Services
            account with a hosted zone that was created with a different Amazon Web Services account, a
            complex type that includes the ID and region of the VPC.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

