package com.gh.gamecenter.forum.home.follow

import com.gh.gamecenter.entity.HistoryGameEntity
import com.gh.gamecenter.entity.PersonalHistoryEntity
import com.gh.gamecenter.feature.entity.AnswerEntity

abstract class FollowDynamicItem {

    abstract val itemType: Int

    fun areItemsTheSame(other: FollowDynamicItem) =
        itemType == other.itemType && doAreItemsTheSame(other)


    fun areContentsTheSame(other: FollowDynamicItem) =
        itemType == other.itemType && doAreContentsTheSame(other)

    protected open fun doAreItemsTheSame(other: FollowDynamicItem) = true

    protected open fun doAreContentsTheSame(other: FollowDynamicItem) = this == other

    companion object {

        const val FOLLOW_DYNAMIC_ITEM_TYPE_FOOTER = -1
        const val FOLLOW_DYNAMIC_ITEM_TYPE_PERSONAL = 0
        const val FOLLOW_DYNAMIC_ITEM_TYPE_BBS = 1
    }
}

data class FollowDynamicPersonalItem(
    val data: PersonalHistoryEntity
) : FollowDynamicItem() {

    override val itemType: Int
        get() = FOLLOW_DYNAMIC_ITEM_TYPE_PERSONAL

    override fun doAreItemsTheSame(other: FollowDynamicItem): Boolean {
        return other is FollowDynamicPersonalItem
                && data.id == other.data.id
    }

}

data class FollowDynamicBbsItem(
    val data: AnswerEntity
) : FollowDynamicItem() {

    override val itemType: Int
        get() = FOLLOW_DYNAMIC_ITEM_TYPE_BBS

    override fun doAreItemsTheSame(other: FollowDynamicItem): Boolean {
        return other is FollowDynamicBbsItem
                && data.id == other.data.id
    }

}

object FollowDynamicFooterItem : FollowDynamicItem() {
    override val itemType: Int
        get() = FOLLOW_DYNAMIC_ITEM_TYPE_FOOTER
}