package xyz.cottongin.radio247.data.db

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.Query
import xyz.cottongin.radio247.data.model.ListeningSession
import kotlinx.coroutines.flow.Flow

@Dao
interface ListeningSessionDao {
    @Insert
    suspend fun insert(session: ListeningSession): Long

    @Query("UPDATE listening_sessions SET endedAt = :endedAt WHERE id = :id")
    suspend fun updateEndedAt(id: Long, endedAt: Long)

    @Query("SELECT * FROM listening_sessions WHERE endedAt IS NULL LIMIT 1")
    suspend fun getActiveSession(): ListeningSession?

    @Query("SELECT * FROM listening_sessions ORDER BY startedAt DESC LIMIT :limit")
    fun getRecentSessions(limit: Int = 50): Flow<List<ListeningSession>>
}
