import somecodes.Codes.Companion.ValidString
import zello.ZelloClient
import zello.ZelloEvent

//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
fun main() {
    val z = ZelloClient.fromConsumerZello()
    z.Start(object : ZelloEvent {
        override fun onChannelStatus(
            channel: String,
            status: String,
            userOnline: Int,
            error: String?,
            errorType: String?
        ) {
            println("Channel Status: $channel is $status with $userOnline users online.")
            if (ValidString(error) && ValidString(errorType)) {
                println("Error: $error, Type: $errorType")
            }
        }

        override fun onAudioData(streamID: Int, from: String, For: String, channel: String, data: ByteArray) {
            println("Audio Data received from $from for $For on channel $channel with streamID $streamID ")
        }

        override fun onThumbnailImage(imageID: Int, from: String, For: String, channel: String, data: ByteArray, timestamp: Long) {
            println("Thumbnail Image received from $from for $For on channel $channel with imageID $imageID at timestamp $timestamp")
        }

        override fun onFullImage(imageID: Int, from: String, For: String, channel: String, data: ByteArray, timestamp: Long) {
            println("Full Image received from $from for $For on channel $channel with imageID $imageID at timestamp $timestamp")
        }

        override fun onTextMessage(messageID: Int, from: String, For: String, channel: String, text: String, timestamp: Long) {
            println("Text Message received from $from for $For on channel $channel with messageID $messageID at timestamp $timestamp. Text: $text")
        }

        override fun onLocation(messageID: Int, from: String, For: String, channel: String, latitude: Double, longitude: Double, address: String, accuracy: Double, timestamp: Long) {
            println("Location received from $from for $For on channel $channel with messageID $messageID at timestamp $timestamp. Location($latitude,$longitude), Address:$address, Accuracy:$accuracy")
        }

        override fun onConnected() {
            println("Connected to Zello server.")
        }

        override fun onDisconnected() {
            println("Disconnected from Zello server.")
        }

        override fun onError(errorMessage: String) {
            println("Error occurred in Zello client: $errorMessage")
        }
    })

}