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

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



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, app_instance_arn: Text, client_request_token: Text, mode: Text = None, privacy: Text = None, metadata: Text = None, tags: List = None, chime_bearer: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a channel to which you can add users and send messages.  Restriction: You can't change a channel's
    privacy.  The x-amz-chime-bearer request header is mandatory. Use the AppInstanceUserArn of the user that makes
    the API call as the value in the header.

    Args:
        name(Text): The name of the channel.
        app_instance_arn(Text): The ARN of the channel request.
        mode(Text, optional): The channel mode: UNRESTRICTED or RESTRICTED. Administrators, moderators, and channel members
            can add themselves and other members to unrestricted channels. Only administrators and
            moderators can add members to restricted channels. Defaults to None.
        privacy(Text, optional): The channel's privacy level: PUBLIC or PRIVATE. Private channels aren't discoverable by users
            outside the channel. Public channels are discoverable by anyone in the AppInstance. Defaults to None.
        metadata(Text, optional): The metadata of the creation request. Limited to 1KB and UTF-8. Defaults to None.
        client_request_token(Text): The client token for the request. An Idempotency token.
        tags(List, optional): The tags for the creation request. Defaults to None.
        chime_bearer(Text, optional): The AppInstanceUserArn of the user that makes the API call. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.chime.create_channel(
                ctx,
                
                
                **{"Name": name, "AppInstanceArn": app_instance_arn, "Mode": mode, "Privacy": privacy, "Metadata": metadata, "ClientRequestToken": client_request_token, "Tags": tags, "ChimeBearer": chime_bearer}
            )
            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.chime.describe_channel(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, channel_arn: Text, chime_bearer: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Immediately makes a channel and its memberships inaccessible and marks them for deletion. This is an
    irreversible process.  The x-amz-chime-bearer request header is mandatory. Use the AppInstanceUserArn of the
    user that makes the API call as the value in the header.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        channel_arn(Text): The ARN of the channel being deleted.
        chime_bearer(Text, optional): The AppInstanceUserArn of the user that makes the API call. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

