package com.adealink.weparty.profile.ui.about.data

import com.adealink.weparty.commonui.recycleview.diffutil.BaseListItemData
import com.adealink.weparty.module.profile.data.UserInfo
import com.adealink.weparty.module.profile.data.UserInterest
import com.adealink.weparty.module.profile.data.UserPlaymateSkill
import com.adealink.weparty.module.profile.data.contentsTheSame
import com.adealink.weparty.profile.dynamic.data.DynamicDetailData
import com.adealink.weparty.profile.dynamic.data.DynamicMediaData

sealed class BaseProfileData : BaseListItemData

data class IntroduceItemData(
    val userInfo: UserInfo
) : BaseProfileData() {
    override fun areContentsTheSame(newItem: Any): Boolean {
        val other = newItem as? IntroduceItemData ?: return false
        return userInfo.contentsTheSame(other.userInfo)
    }
}

data class InterestsItemData(
    val interests: List<UserInterest>
) : BaseProfileData() {
    override fun areContentsTheSame(newItem: Any): Boolean {
        val other = newItem as? InterestsItemData ?: return false
        if (interests.size != other.interests.size) {
            return false
        }
        for ((index, skill) in interests.withIndex()) {
            if (skill != other.interests[index]) {
                return false
            }
        }
        return true
    }
}

data class SkillsItemData(
    val skills: List<UserPlaymateSkill>
) : BaseProfileData() {
    override fun areContentsTheSame(newItem: Any): Boolean {
        val other = newItem as? SkillsItemData ?: return false
        if (skills.size != other.skills.size) {
            return false
        }
        for ((index, skill) in skills.withIndex()) {
            if (skill != other.skills[index]) {
                return false
            }
        }
        return true
    }
}

object EmptyItemData : BaseProfileData() {
    override fun areContentsTheSame(newItem: Any): Boolean {
        return true
    }
}

object DynamicTitleItemData : BaseProfileData() {
    override fun areContentsTheSame(newItem: Any): Boolean {
        return true
    }
}

data class DynamicItemData(
    val dynamic: DynamicDetailData,
    val userInfo: UserInfo?
) : BaseProfileData() {
    override fun areContentsTheSame(newItem: Any): Boolean {
        val other = newItem as? DynamicItemData ?: return false
        return dynamic == other.dynamic
    }
}


sealed class BaseDynamicPhotoItem : BaseListItemData

data class DynamicPhotoItemData(
    val data: DynamicMediaData?
) : BaseDynamicPhotoItem() {
    override fun areContentsTheSame(newItem: Any): Boolean {
        val other = newItem as? DynamicPhotoItemData ?: return false
        return data == other.data
    }
}

class DynamicEmptyItemData() : BaseDynamicPhotoItem() {
    override fun areContentsTheSame(newItem: Any): Boolean {
        return true
    }
}