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

hub.exec.boto3.client.docdb.create_global_cluster
hub.exec.boto3.client.docdb.delete_global_cluster
hub.exec.boto3.client.docdb.describe_global_clusters
hub.exec.boto3.client.docdb.modify_global_cluster
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, global_cluster_identifier: Text, source_db_cluster_identifier: Text = None, engine: Text = None, engine_version: Text = None, deletion_protection: bool = None, database_name: Text = None, storage_encrypted: bool = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates an Amazon DocumentDB global cluster that can span multiple multiple Regions. The global cluster contains
    one primary cluster with read-write capability, and up-to give read-only secondary clusters. Global clusters
    uses storage-based fast replication across regions with latencies less than one second, using dedicated
    infrastructure with no impact to your workload’s performance.  You can create a global cluster that is initially
    empty, and then add a primary and a secondary to it. Or you can specify an existing cluster during the create
    operation, and this cluster becomes the primary of the global cluster.   This action only applies to Amazon
    DocumentDB clusters.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        global_cluster_identifier(Text): The cluster identifier of the new global cluster.
        source_db_cluster_identifier(Text, optional): The Amazon Resource Name (ARN) to use as the primary cluster of the global cluster. This
            parameter is optional. Defaults to None.
        engine(Text, optional): The name of the database engine to be used for this cluster. Defaults to None.
        engine_version(Text, optional): The engine version of the global cluster. Defaults to None.
        deletion_protection(bool, optional): The deletion protection setting for the new global cluster. The global cluster can't be deleted
            when deletion protection is enabled. Defaults to None.
        database_name(Text, optional): The name for your database of up to 64 alpha-numeric characters. If you do not provide a name,
            Amazon DocumentDB will not create a database in the global cluster you are creating. Defaults to None.
        storage_encrypted(bool, optional): The storage encryption setting for the new global cluster. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.docdb.create_global_cluster(
                ctx,
                
                
                **{"GlobalClusterIdentifier": global_cluster_identifier, "SourceDBClusterIdentifier": source_db_cluster_identifier, "Engine": engine, "EngineVersion": engine_version, "DeletionProtection": deletion_protection, "DatabaseName": database_name, "StorageEncrypted": storage_encrypted}
            )
            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.docdb.describe_global_clusters(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, global_cluster_identifier: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a global cluster. The primary and secondary clusters must already be detached or deleted before
    attempting to delete a global cluster.  This action only applies to Amazon DocumentDB clusters.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        global_cluster_identifier(Text): The cluster identifier of the global cluster being deleted.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

