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

hub.exec.boto3.client.iot.create_stream
hub.exec.boto3.client.iot.delete_stream
hub.exec.boto3.client.iot.describe_stream
hub.exec.boto3.client.iot.list_streams
hub.exec.boto3.client.iot.update_stream
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, stream_id: Text, files: List, role_arn: Text, description: Text = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a stream for delivering one or more large files in chunks over MQTT. A stream transports data bytes in
    chunks or blocks packaged as MQTT messages from a source like S3. You can have one or more files associated with
    a stream.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        stream_id(Text): The stream ID.
        description(Text, optional): A description of the stream. Defaults to None.
        files(List): The files to stream.
        role_arn(Text): An IAM role that allows the IoT service principal assumes to access your S3 files.
        tags(List, optional): Metadata which can be used to manage streams. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.iot.create_stream(
                ctx,
                
                
                **{"streamId": stream_id, "description": description, "files": files, "roleArn": role_arn, "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.iot.describe_stream(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, stream_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a stream.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        stream_id(Text): The stream ID.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

