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

hub.exec.boto3.client.ivs.create_channel
hub.exec.boto3.client.ivs.delete_channel
hub.exec.boto3.client.ivs.get_channel
hub.exec.boto3.client.ivs.list_channels
hub.exec.boto3.client.ivs.update_channel
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text = None, latency_mode: Text = None, type_: Text = None, authorized: bool = None, recording_configuration_arn: Text = None, tags: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a new channel and an associated stream key to start streaming.

    Args:
        name(Text, optional): Channel name. Defaults to None.
        latency_mode(Text, optional): Channel latency mode. Use NORMAL to broadcast and deliver live video up to Full HD. Use LOW for
            near-real-time interaction with viewers. (Note: In the Amazon IVS console, LOW and NORMAL
            correspond to Ultra-low and Standard, respectively.) Default: LOW. Defaults to None.
        type_(Text, optional): Channel type, which determines the allowable resolution and bitrate. If you exceed the allowable
            resolution or bitrate, the stream probably will disconnect immediately. Default: STANDARD. Valid
            values:    STANDARD: Multiple qualities are generated from the original input, to automatically
            give viewers the best experience for their devices and network conditions. Vertical resolution
            can be up to 1080 and bitrate can be up to 8.5 Mbps.    BASIC: Amazon IVS delivers the original
            input to viewers. The viewer’s video-quality choice is limited to the original input. Vertical
            resolution can be up to 480 and bitrate can be up to 1.5 Mbps. Defaults to None.
        authorized(bool, optional): Whether the channel is private (enabled for playback authorization). Default: false. Defaults to None.
        recording_configuration_arn(Text, optional): Recording-configuration ARN. Default: "" (empty string, recording is disabled). Defaults to None.
        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.channel.present:
                - 
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.ivs.channel.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_channel(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.ivs.create_channel(
                ctx,
                
                
                **{"Name": name, "latencyMode": latency_mode, "type": type_, "authorized": authorized, "recordingConfigurationArn": recording_configuration_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_channel(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 specified channel and its associated stream keys. If you try to delete a live channel, you will get
    an error (409 ConflictException). To delete a channel that is live, call StopStream, wait for the Amazon
    EventBridge "Stream End" event (to verify that the stream's state was changed from Live to Offline), then call
    DeleteChannel. (See  Using EventBridge with Amazon IVS.)

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

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

