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

hub.exec.boto3.client.iotanalytics.create_channel
hub.exec.boto3.client.iotanalytics.delete_channel
hub.exec.boto3.client.iotanalytics.describe_channel
hub.exec.boto3.client.iotanalytics.list_channels
hub.exec.boto3.client.iotanalytics.update_channel
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, channel_name: Text, channel_storage: Dict = None, retention_period: Dict = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Used to create a channel. A channel collects data from an MQTT topic and archives the raw, unprocessed messages
    before publishing the data to a pipeline.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        channel_name(Text): The name of the channel.
        channel_storage(Dict, optional): Where channel data is stored. You can choose one of serviceManagedS3 or customerManagedS3
            storage. If not specified, the default is serviceManagedS3. You can't change this storage option
            after the channel is created. Defaults to None.
        retention_period(Dict, optional): How long, in days, message data is kept for the channel. When customerManagedS3 storage is
            selected, this parameter is ignored. Defaults to None.
        tags(List, optional): Metadata which can be used to manage the channel. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.iotanalytics.create_channel(
                ctx,
                
                
                **{"channelName": channel_name, "channelStorage": channel_storage, "retentionPeriod": retention_period, "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.iotanalytics.describe_channel(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, channel_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified channel.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        channel_name(Text): The name of the channel to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

