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

hub.exec.boto3.client.rds.create_db_cluster_endpoint
hub.exec.boto3.client.rds.delete_db_cluster_endpoint
hub.exec.boto3.client.rds.describe_db_cluster_endpoints
hub.exec.boto3.client.rds.modify_db_cluster_endpoint
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, db_cluster_identifier: Text, db_cluster_endpoint_identifier: Text, endpoint_type: Text, static_members: List = None, excluded_members: List = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a new custom endpoint and associates it with an Amazon Aurora DB cluster.  This action only applies to
    Aurora DB clusters.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        db_cluster_identifier(Text): The DB cluster identifier of the DB cluster associated with the endpoint. This parameter is
            stored as a lowercase string.
        db_cluster_endpoint_identifier(Text): The identifier to use for the new endpoint. This parameter is stored as a lowercase string.
        endpoint_type(Text): The type of the endpoint. One of: READER, WRITER, ANY.
        static_members(List, optional): List of DB instance identifiers that are part of the custom endpoint group. Defaults to None.
        excluded_members(List, optional): List of DB instance identifiers that aren't part of the custom endpoint group. All other
            eligible instances are reachable through the custom endpoint. Only relevant if the list of
            static members is empty. Defaults to None.
        tags(List, optional): The tags to be assigned to the Amazon RDS resource. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.rds.db_cluster_endpoint.present:
                - name: value
                - db_cluster_identifier: value
                - db_cluster_endpoint_identifier: value
                - endpoint_type: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.rds.db_cluster_endpoint.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.rds.describe_db_cluster_endpoints(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.rds.create_db_cluster_endpoint(
                ctx,
                
                
                **{"DBClusterIdentifier": db_cluster_identifier, "DBClusterEndpointIdentifier": db_cluster_endpoint_identifier, "EndpointType": endpoint_type, "StaticMembers": static_members, "ExcludedMembers": excluded_members, "Tags": tags}
            )
            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.rds.describe_db_cluster_endpoints(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, db_cluster_endpoint_identifier: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a custom endpoint and removes it from an Amazon Aurora DB cluster.  This action only applies to Aurora
    DB clusters.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        db_cluster_endpoint_identifier(Text): The identifier associated with the custom endpoint. This parameter is stored as a lowercase
            string.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

