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

hub.exec.boto3.client.rds.create_global_cluster
hub.exec.boto3.client.rds.delete_global_cluster
hub.exec.boto3.client.rds.describe_global_clusters
hub.exec.boto3.client.rds.failover_global_cluster
hub.exec.boto3.client.rds.modify_global_cluster
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, global_cluster_identifier: Text = None, 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 Aurora global database spread across multiple Amazon Web Services Regions. The global database
    contains a single primary cluster with read-write capability, and a read-only secondary cluster that receives
    data from the primary cluster through high-speed replication performed by the Aurora storage subsystem.   You
    can create a global database that is initially empty, and then add a primary cluster and a secondary cluster to
    it. Or you can specify an existing Aurora cluster during the create operation, and this cluster becomes the
    primary cluster of the global database.   This action only applies to Aurora DB clusters.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        global_cluster_identifier(Text, optional): The cluster identifier of the new global database cluster. Defaults to None.
        source_db_cluster_identifier(Text, optional):  The Amazon Resource Name (ARN) to use as the primary cluster of the global database. This
            parameter is optional. Defaults to None.
        engine(Text, optional): The name of the database engine to be used for this DB cluster. Defaults to None.
        engine_version(Text, optional): The engine version of the Aurora global database. Defaults to None.
        deletion_protection(bool, optional):  The deletion protection setting for the new global database. The global database 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 Aurora will not create a database in the global database cluster you are creating. Defaults to None.
        storage_encrypted(bool, optional):  The storage encryption setting for the new global database cluster. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.rds.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.rds.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 database cluster. The primary and secondary clusters must already be detached or destroyed
    first.   This action only applies to Aurora DB 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 database cluster being deleted.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

