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

hub.exec.boto3.client.kinesis.deregister_stream_consumer
hub.exec.boto3.client.kinesis.describe_stream_consumer
hub.exec.boto3.client.kinesis.list_stream_consumers
hub.exec.boto3.client.kinesis.register_stream_consumer
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, stream_arn: Text, consumer_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Registers a consumer with a Kinesis data stream. When you use this operation, the consumer you register can then
    call SubscribeToShard to receive data from the stream using enhanced fan-out, at a rate of up to 2 MiB per
    second for every shard you subscribe to. This rate is unaffected by the total number of consumers that read from
    the same stream. You can register up to 20 consumers per stream. A given consumer can only be registered with
    one stream at a time. For an example of how to use this operations, see Enhanced Fan-Out Using the Kinesis Data
    Streams API. The use of this operation has a limit of five transactions per second per account. Also, only 5
    consumers can be created simultaneously. In other words, you cannot have more than 5 consumers in a CREATING
    status at the same time. Registering a 6th consumer while there are 5 in a CREATING status results in a
    LimitExceededException.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        stream_arn(Text): The ARN of the Kinesis data stream that you want to register the consumer with. For more info,
            see Amazon Resource Names (ARNs) and AWS Service Namespaces.
        consumer_name(Text): For a given Kinesis data stream, each consumer must have a unique name. However, consumer names
            don't have to be unique across data streams.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.kinesis.register_stream_consumer(
                ctx,
                
                
                **{"StreamARN": stream_arn, "ConsumerName": consumer_name}
            )
            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.kinesis.describe_stream_consumer(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, stream_arn: Text = None, consumer_name: Text = None, consumer_arn: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    To deregister a consumer, provide its ARN. Alternatively, you can provide the ARN of the data stream and the
    name you gave the consumer when you registered it. You may also provide all three parameters, as long as they
    don't conflict with each other. If you don't know the name or ARN of the consumer that you want to deregister,
    you can use the ListStreamConsumers operation to get a list of the descriptions of all the consumers that are
    currently registered with a given data stream. The description of a consumer contains its name and ARN. This
    operation has a limit of five transactions per second per stream.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        stream_arn(Text, optional): The ARN of the Kinesis data stream that the consumer is registered with. For more information,
            see Amazon Resource Names (ARNs) and AWS Service Namespaces. Defaults to None.
        consumer_name(Text, optional): The name that you gave to the consumer. Defaults to None.
        consumer_arn(Text, optional): The ARN returned by Kinesis Data Streams when you registered the consumer. If you don't know the
            ARN of the consumer that you want to deregister, you can use the ListStreamConsumers operation
            to get a list of the descriptions of all the consumers that are currently registered with a
            given data stream. The description of a consumer contains its ARN. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.kinesis.deregister_stream_consumer(
                ctx,
                
                
                **{"StreamARN": stream_arn, "ConsumerName": consumer_name, "ConsumerARN": consumer_arn}
            )
            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.kinesis.describe_stream_consumer(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

