package com.tencent.liteav.demo.superplayer.database.dao

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy.REPLACE
import androidx.room.Query
import com.tencent.liteav.demo.superplayer.database.entity.History
import kotlinx.coroutines.flow.Flow

@Dao
public interface HistoryDao {
    @Query("SELECT * FROM history WHERE course_id = :courseId")
    fun getById(courseId: String): Flow<List<History>>

    @Insert(onConflict = REPLACE)
    fun insertHistory(history: History)

    @Insert
    fun insertHistories(vararg histories: History)

    @Query("SELECT COUNT(DISTINCT(section_id)) FROM History WHERE date = :date AND course_id = :courseId AND ct_id = :countDown")
    fun queryTodayEpisodeHistory(
        courseId: String,
        countDown: String,
        date: String,
    ): Int

    @Query("SELECT * FROM History WHERE date = :date AND course_id = :courseId AND ct_id = :countDown;")
    fun queryTodayDurationHistory(
        courseId: String,
        countDown: String,
        date: String,
    ): List<History>

    @Query("SELECT DISTINCT section_id FROM History WHERE course_id = :courseId")
    fun queryAllHistory(courseId: String): List<String>

    @Query("SELECT * FROM History WHERE course_id = :courseId AND section_id = :sectionId")
    fun queryAllSectionHistory(courseId: String, sectionId: String): List<History>

    @Query("DELETE FROM History WHERE course_id = :courseId")
    fun deleteAllHistory(courseId:String)
}