package rasel.lunar.launcher.model

import io.realm.kotlin.ext.realmListOf
import io.realm.kotlin.types.RealmList
import io.realm.kotlin.types.RealmObject
import io.realm.kotlin.types.annotations.Ignore
import io.realm.kotlin.types.annotations.PrimaryKey

class TelegramBotUpdate  : RealmObject {
    var ok : String? = null
    @Ignore
    var result : ArrayList<TelegramData> = arrayListOf()
    var list : RealmList<TelegramData> = realmListOf()
    fun isOK() = "true".equals(ok)
    fun fill() {
        list.clear()
        list.addAll(result)
        list.forEach {
            it.fill()
        }
    }

}

class TelegramData  : RealmObject{
    fun fill() {
        message?.fill()
    }

    @PrimaryKey
    var update_id : Long = 0L
    var message : TelegramMessage? = null
    var my_chat_member : TelegramMessage? = null
}

class TelegramMessage  : RealmObject{
    fun fill() {
        commandEentitie.clear()
        commandEentitie.addAll(entities)
    }

    @PrimaryKey
    var message_id : Long = 0L
    var from : TelegramFrom? = null
    var chat : TelegramChat? = null
    var date : Long = 0L
    var text : String? = null
    @Ignore
    var entities : ArrayList<BotCommandEentitie> = arrayListOf()
        set(n) {
            commandEentitie.clear()
            commandEentitie.addAll(n)
        }
    var commandEentitie : RealmList<BotCommandEentitie> = realmListOf()
}

class TelegramChat  : RealmObject{
    @PrimaryKey
    var id  :Long = 0L
    var language_code : String? = null
    var is_bot : String? = null //"id": 7068729507,
    var first_name  : String? = null          //"first_name": "BUM",
    var last_name  : String? = null            //"last_name": "Han",
    var type  : String? = null            //"type": "private"
}

class BotCommandEentitie  : RealmObject{
    var offset : Int = 0
    var length : Int = 0
    var type : String? = null
}

class TelegramFrom : RealmObject {
    @PrimaryKey
    var id  :Long = 0L
    var language_code : String? = null
    var is_bot : String? = null //"id": 7068729507,
    var first_name  : String? = null          //"first_name": "BUM",
    var last_name  : String? = null            //"last_name": "Han",
    var type  : String? = null            //"type": "private"
}