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

hub.exec.boto3.client.kinesisvideo.create_stream
hub.exec.boto3.client.kinesisvideo.delete_stream
hub.exec.boto3.client.kinesisvideo.describe_stream
hub.exec.boto3.client.kinesisvideo.list_streams
hub.exec.boto3.client.kinesisvideo.tag_stream
hub.exec.boto3.client.kinesisvideo.untag_stream
hub.exec.boto3.client.kinesisvideo.update_stream
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, stream_name: Text, device_name: Text = None, media_type: Text = None, kms_key_id: Text = None, data_retention_in_hours: int = None, tags: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a new Kinesis video stream.  When you create a new stream, Kinesis Video Streams assigns it a version
    number. When you change the stream's metadata, Kinesis Video Streams updates the version.   CreateStream is an
    asynchronous operation. For information about how the service works, see How it Works.  You must have
    permissions for the KinesisVideo:CreateStream action.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        device_name(Text, optional): The name of the device that is writing to the stream.   In the current implementation, Kinesis
            Video Streams does not use this name. Defaults to None.
        stream_name(Text): A name for the stream that you are creating. The stream name is an identifier for the stream,
            and must be unique for each account and region.
        media_type(Text, optional): The media type of the stream. Consumers of the stream can use this information when processing
            the stream. For more information about media types, see Media Types. If you choose to specify
            the MediaType, see Naming Requirements for guidelines. Example valid values include "video/h264"
            and "video/h264,audio/aac". This parameter is optional; the default value is null (or empty in
            JSON). Defaults to None.
        kms_key_id(Text, optional): The ID of the AWS Key Management Service (AWS KMS) key that you want Kinesis Video Streams to
            use to encrypt stream data. If no key ID is specified, the default, Kinesis Video-managed key
            (aws/kinesisvideo) is used.  For more information, see DescribeKey. Defaults to None.
        data_retention_in_hours(int, optional): The number of hours that you want to retain the data in the stream. Kinesis Video Streams
            retains the data in a data store that is associated with the stream. The default value is 0,
            indicating that the stream does not persist data. When the DataRetentionInHours value is 0,
            consumers can still consume the fragments that remain in the service host buffer, which has a
            retention time limit of 5 minutes and a retention memory limit of 200 MB. Fragments are removed
            from the buffer when either limit is reached. Defaults to None.
        tags(Dict, optional): A list of tags to associate with the specified stream. Each tag is a key-value pair (the value
            is optional). Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.kinesisvideo.create_stream(
                ctx,
                
                
                **{"DeviceName": device_name, "StreamName": stream_name, "MediaType": media_type, "KmsKeyId": kms_key_id, "DataRetentionInHours": data_retention_in_hours, "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.kinesisvideo.describe_stream(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, stream_arn: Text, current_version: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a Kinesis video stream and the data contained in the stream.  This method marks the stream for deletion,
    and makes the data in the stream inaccessible immediately.    To ensure that you have the latest version of the
    stream before deleting it, you can specify the stream version. Kinesis Video Streams assigns a version to each
    stream. When you update a stream, Kinesis Video Streams assigns a new version number. To get the latest stream
    version, use the DescribeStream API.  This operation requires permission for the KinesisVideo:DeleteStream
    action.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        stream_arn(Text): The Amazon Resource Name (ARN) of the stream that you want to delete.
        current_version(Text, optional): Optional: The version of the stream that you want to delete.  Specify the version as a safeguard
            to ensure that your are deleting the correct stream. To get the stream version, use the
            DescribeStream API. If not specified, only the CreationTime is checked before deleting the
            stream. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

