package rasel.lunar.launcher.model

import rasel.lunar.launcher.beforeDay
import rasel.lunar.launcher.utils.JamoUtils
import java.util.Date

class MissD : RssDataInterface {
    var link : String? = null

    var title : String? = null

    var thumb : String? = null

    var desc : String? = null

    override fun title(): String {
        return title ?: ""
    }

    override fun thumbnailUrl(): String {
        return thumb ?: ""
    }

    override fun originPage(): String {
        return link ?: ""
    }

    override fun description(): String {
        return desc ?: ""
    }

    override fun pubDate(): Long {
        return beforeDay(Date())
    }

    override fun category(): RssDataType {
        return RssDataType.GURU
    }

    override fun getCho(): String? {
        return JamoUtils.split(title!!).joinToString("")
    }
}

class MostItem : JGuru , RssDataInterface {

    constructor() : super()

    override fun title(): String {
        return title
    }

    override fun thumbnailUrl(): String {
        return image
    }

    override fun originPage(): String {
        return pageLink
    }

    override fun description(): String {
        return tags.plus(", ").plus(model).plus(", ").plus(category())
    }

    override fun pubDate(): Long {
        return date
    }

    override fun category(): RssDataType {
        return RssDataType.Most
    }

    override fun getCho(): String? {
        return JamoUtils.split(title!!).joinToString("")
    }
}
open class JGuru : RssDataInterface {
    var model : String = ""
    var title : String = ""
    var pageLink : String = ""
    var image : String = ""
    var tags : String = ""
    var date : Long = 0L

    constructor(
        model: String,
        title: String,
        pageLink: String,
        image: String,
        tags: String,
        date: Long
    ) {
        this.model = model
        this.title = title
        this.pageLink = pageLink
        this.image = image
        this.tags = tags
        this.date = date
    }

    constructor()

    override fun title(): String {
        return title
    }

    override fun thumbnailUrl(): String {
        return image
    }

    override fun originPage(): String {
        return pageLink
    }

    override fun description(): String {
        return tags.plus(", ").plus(model).plus(", ").plus(category())
    }

    override fun pubDate(): Long {
        return date
    }

    override fun category(): RssDataType {
        return RssDataType.GURU
    }

    fun isValid() = (((pageLink.length ?:0) > 0) && ((title.length ?:0) > 0)&& ((image.length ?:0) > 0))

    override fun getCho(): String? {
        return JamoUtils.split(title!!).joinToString("")
    }
}

class jGuruTag : RssDataInterface {
    var link : String = ""
    var tagTitle = ""
    var count = 0

    override fun title(): String {
        return tagTitle
    }

    override fun thumbnailUrl(): String {
        return ""
    }

    override fun originPage(): String {
        return link
    }

    override fun description(): String {
        return " "
    }

    override fun pubDate(): Long {
        return count.toLong()
    }

    override fun category(): RssDataType {
        return RssDataType.TAGS
    }

    constructor(link: String, tagTitle: String) {
        this.link = link
        this.tagTitle = tagTitle
        if (tagTitle.contains("(") && tagTitle.contains(")")) {
            try {
                count = tagTitle.split("(")[1].split(")")[0].toInt()
            }catch (e : Exception) {}
        }
    }
    override fun getCho(): String? {
        return JamoUtils.split(tagTitle!!).joinToString("")
    }
}
