package com.gamedog.vididin.manager.taskbeans

import com.gamedog.vididin.main.fragments.task.RewardDetail
import com.gamedog.vididin.manager.taskbeans.BaseTaskState.Companion.STATE_ONGOING
import kotlinx.serialization.Serializable
import kotlin.collections.forEach


@Serializable
abstract class BaseDailyTaskState : BaseTaskState() {
    protected val mSubTaskRewardState: MutableList<SubDailyTaskBean> = mutableListOf()

    abstract fun getTodayWatchedCount(): Int
    abstract fun addWatchedCount(newWatchedNum: Int)
    abstract fun addWatchedVideoInfo(dataPair: Pair<String, Long>): Boolean


    fun getSubTaskRewardState(): List<SubDailyTaskBean> {
        return mSubTaskRewardState
    }

    fun isAllTaskFinish(): Boolean {
        return mSubTaskRewardState.all { it.state >= STATE_CLAIMED }
    }

    fun initSubTaskRewardList(subTasks: List<RewardDetail>) {
        mSubTaskRewardState.clear()

        subTasks.forEach {
            mSubTaskRewardState.add(SubDailyTaskBean(it.value, it.target_count, STATE_ONGOING))
        }
    }
}

data class SubDailyTaskBean(
    val mRewardNum: Int,
    val mTargetAdCount: Int,
    var state: Int = STATE_ONGOING,)