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

hub.exec.boto3.client.ivs.create_stream_key
hub.exec.boto3.client.ivs.delete_stream_key
hub.exec.boto3.client.ivs.get_stream_key
hub.exec.boto3.client.ivs.list_stream_keys
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, channel_arn: Text, tags: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a stream key, used to initiate a stream, for the specified channel ARN. Note that CreateChannel creates
    a stream key. If you subsequently use CreateStreamKey on the same channel, it will fail because a stream key
    already exists and there is a limit of 1 stream key per channel. To reset the stream key on a channel, use
    DeleteStreamKey and then CreateStreamKey.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        channel_arn(Text): ARN of the channel for which to create the stream key.
        tags(Dict, optional): Array of 1-50 maps, each of the form string:string (key:value). Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.ivs.create_stream_key(
                ctx,
                
                
                **{"channelArn": channel_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.ivs.get_stream_key(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, arn: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the stream key for the specified ARN, so it can no longer be used to stream.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        arn(Text): ARN of the stream key to be deleted.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

