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

hub.exec.boto3.client.kafka.create_cluster
hub.exec.boto3.client.kafka.delete_cluster
hub.exec.boto3.client.kafka.describe_cluster
hub.exec.boto3.client.kafka.list_clusters
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, broker_node_group_info: Dict, cluster_name: Text, kafka_version: Text, number_of_broker_nodes: int, client_authentication: Dict = None, configuration_info: Dict = None, encryption_info: Dict = None, enhanced_monitoring: Text = None, open_monitoring: Dict = None, logging_info: Dict = None, tags: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
     Creates a new MSK cluster.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        broker_node_group_info(Dict):  Information about the broker nodes in the cluster.
        client_authentication(Dict, optional):  Includes all client authentication related information. Defaults to None.
        cluster_name(Text):  The name of the cluster.
        configuration_info(Dict, optional):  Represents the configuration that you want MSK to use for the brokers in a cluster. Defaults to None.
        encryption_info(Dict, optional):  Includes all encryption-related information. Defaults to None.
        enhanced_monitoring(Text, optional):  Specifies the level of monitoring for the MSK cluster. The possible values are DEFAULT,
            PER_BROKER, PER_TOPIC_PER_BROKER, and PER_TOPIC_PER_PARTITION. Defaults to None.
        open_monitoring(Dict, optional):  The settings for open monitoring. Defaults to None.
        kafka_version(Text):  The version of Apache Kafka.
        logging_info(Dict, optional): . Defaults to None.
        number_of_broker_nodes(int):  The number of broker nodes in the cluster.
        tags(Dict, optional):  Create tags when creating the cluster. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.kafka.cluster.present:
                - name: value
                - broker_node_group_info: value
                - cluster_name: value
                - kafka_version: value
                - number_of_broker_nodes: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.kafka.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.kafka.describe_cluster(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.kafka.create_cluster(
                ctx,
                
                
                **{"BrokerNodeGroupInfo": broker_node_group_info, "ClientAuthentication": client_authentication, "ClusterName": cluster_name, "ConfigurationInfo": configuration_info, "EncryptionInfo": encryption_info, "EnhancedMonitoring": enhanced_monitoring, "OpenMonitoring": open_monitoring, "KafkaVersion": kafka_version, "LoggingInfo": logging_info, "NumberOfBrokerNodes": number_of_broker_nodes, "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.kafka.describe_cluster(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, cluster_arn: Text, current_version: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
     Deletes the MSK cluster specified by the Amazon Resource Name (ARN) in the request.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        cluster_arn(Text):  The Amazon Resource Name (ARN) that uniquely identifies the cluster.
        current_version(Text, optional):  The current version of the MSK cluster. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.kafka.delete_cluster(
                ctx,
                
                
                **{"ClusterArn": cluster_arn, "CurrentVersion": current_version}
            )
            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.kafka.describe_cluster(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

