package com.mime.dualscreenview.data.model

import android.content.pm.ActivityInfo
import io.realm.kotlin.types.RealmObject
import io.realm.kotlin.types.annotations.PrimaryKey
import java.text.SimpleDateFormat
import java.util.Date


class LastInfo() : RealmObject {
    @PrimaryKey
    var _id : String = "UniqLastId"
    var pageUrl : String = ""
    var title : String = ""
    var chapter : Int = 0
    var pageIndex : Int = 0
    var contentsName : String = ""
    var displayOrientation : Int =  ActivityInfo.SCREEN_ORIENTATION_PORTRAIT

    fun makeHistoryItem() : HistoryItem = HistoryItem().apply {
        title = this@LastInfo.title
        pageUrl = this@LastInfo.pageUrl
        chapter = this@LastInfo.chapter
        pageIndex = this@LastInfo.pageIndex
        contentsName = this@LastInfo.contentsName
        displayOrientation = this@LastInfo.displayOrientation
    }
}
class HistoryItem() : RealmObject {
    @PrimaryKey
    var title : String = ""
    var pageUrl : String = ""
    var chapter : Int = 0
    var pageIndex : Int = 0
    var contentsName : String = ""
    var displayOrientation : Int =  ActivityInfo.SCREEN_ORIENTATION_PORTRAIT

    fun makeLastInfo()  = LastInfo().apply{
        _id = "UniqLastId"
        title = this@HistoryItem.title
        pageUrl = this@HistoryItem.pageUrl
        chapter = this@HistoryItem.chapter
        pageIndex = this@HistoryItem.pageIndex
        contentsName = this@HistoryItem.contentsName
        displayOrientation = this@HistoryItem.displayOrientation
    }
    fun putHistory(bookPageInfo: BookPageInfo? , currentPath : String) : HistoryItem {
        title  = bookPageInfo?.bookTitle ?: SimpleDateFormat("YY-mm-DD-HH:mm").format(Date())
        pageUrl  = bookPageInfo?.pathUrl ?: ""
        chapter  = bookPageInfo?.chapterNum ?: 0
        pageIndex  = bookPageInfo?.lastPage ?: 0
        contentsName  = bookPageInfo?.chapterTitle ?: ""
        return this
    }
}
class Bookmark() : RealmObject {
    @PrimaryKey
    var pageUrl : String = ""
}


