package com.radiola.data.local.dao

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.Query
import com.radiola.data.local.entity.RecognizedTrackEntity
import kotlinx.coroutines.flow.Flow

@Dao
interface RecognizedTrackDao {

    @Query("SELECT * FROM recognized_track ORDER BY timestamp DESC LIMIT 200")
    fun getAll(): Flow<List<RecognizedTrackEntity>>

    @Insert
    suspend fun insert(track: RecognizedTrackEntity)

    @Query("DELETE FROM recognized_track WHERE id NOT IN (SELECT id FROM recognized_track ORDER BY timestamp DESC LIMIT 200)")
    suspend fun cleanupOld()
}
