package com.mime.dualscreenview.data.model

import com.mime.dualscreenview.common.Blog
import io.realm.kotlin.ext.realmListOf
import io.realm.kotlin.types.RealmList
import io.realm.kotlin.types.RealmObject
import io.realm.kotlin.types.RealmSet
import io.realm.kotlin.types.annotations.PrimaryKey



class BookPageInfosJ : RealmObject {
    var bookTitle : String = ""
    var bookPageUrl : String = ""
    var pages : ArrayList<BookPageInfoJ> = arrayListOf<BookPageInfoJ>()
    fun getTitleArray() : ArrayList<String> {
        var arrayList = ArrayList<String>()
        pages?.forEach { arrayList.add(it.bookTitle ?: "") }
        return arrayList
    }

    fun getR() : BookPageInfos{
        var r = BookPageInfos()
        r.bookTitle = this.bookTitle
        r.bookPageUrl = this.bookPageUrl
//         for (item in this.pages) {
////             Blog.LOGE("item >>> ${item}")
//             r.pages.add(item.getRealm())
//         }
        return r
    }
}
class BookPageInfoJ : RealmObject {
    var chapterID : Int = 0
    var contents : String? = ""
    var bookPageUrl : String? = ""
    var chapterTitle : String? = ""
    var bookTitle : String? = ""
    var chapterNum : Int = 0
    var lastPage : Int? = 0
    var pathUrl : String? = ""

    fun getRealm() : BookPageInfo {
        var r = BookPageInfo()
        r.chapterID = this.chapterID
        r.contents = this.contents
        r.bookPageUrl = this.bookPageUrl ?: ""
        r.chapterTitle = this.chapterTitle
        r.bookTitle = this.bookTitle ?: ""
        r.chapterNum = this.chapterNum
        r.lastPage = this.lastPage
        r.pathUrl = this.pathUrl?.replace("'","")

        return r
    }
}


class BookPageInfos : RealmObject {
    var bookTitle : String = ""
    @PrimaryKey
    var bookPageUrl : String? = ""
    var pages : RealmList<BookPageInfo> = realmListOf()
    fun getTitleArray() : ArrayList<String> {
        var arrayList = ArrayList<String>()

        pages?.forEach {
            Blog.LOGE("chapterTitle >> ${it.chapterTitle} ")
            arrayList.add(it.chapterTitle ?: "") }
        return arrayList
    }



}
class BookPageInfo : RealmObject {
    var chapterID : Int = 0
    var contents : String? = ""

    var bookPageUrl : String? = ""
    var chapterTitle : String? = ""
    var bookTitle : String? = ""
    var chapterNum : Int = 0
    var lastPage : Int? = 0
    @PrimaryKey
    var pathUrl : String? = ""


}