package com.tencent.liteav.demo.player.util

import com.tencent.liteav.demo.player.util.ModelCourse.Course
import com.tencent.liteav.demo.superplayer.SuperPlayerModel

object ModelProvider {
    private lateinit var course: Course

    fun setData(course: Course) {
        this.course = course
    }

    val courseId: String get() = course.id
    val cccccc: Course get() = course

    val records: List<ModelCourse.Records>
        get() {
            val list = ArrayList<ModelCourse.Records>()
            for (chapter in course.chapterList) {
                for (section in chapter.itemList) {
                    section.getRecord.aiCourseItemId = section.id
                    list.add(section.getRecord)
                }
            }
            return list
        }

    val list: List<SuperPlayerModel>
        get() {
            val list: MutableList<SuperPlayerModel> = ArrayList()
            val paidStatus = course.hasPaid == 1 ///已付费

            for (chapter in course.chapterList) {
                for (section in chapter.itemList) {
                    val model = SuperPlayerModel()
                    model.title = section.name
                    model.duration = section.video.duration.toInt()
                    model.isEnableCache = true
                    model.url = section.video.videoUrl
                    model.sectionId = section.id
                    model.cover = section.imgCover
                    model.isLock = !paidStatus and (section.payType == 0)
                    model.isFree = !paidStatus and (section.payType == 1)
                    list.add(model)
                }
            }

            list[list.size - 1].isLast = true
            return list
        }
}