package xyz.cottongin.radio247.data.db

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

@Dao
interface MetadataSnapshotDao {
    @Insert
    suspend fun insert(snapshot: MetadataSnapshot): Long

    @Query("SELECT * FROM metadata_snapshots WHERE stationId = :stationId ORDER BY timestamp DESC LIMIT :limit")
    fun getByStation(stationId: Long, limit: Int = 50): Flow<List<MetadataSnapshot>>

    @Query("SELECT * FROM metadata_snapshots ORDER BY timestamp DESC LIMIT :limit")
    fun getRecent(limit: Int = 100): Flow<List<MetadataSnapshot>>

    @Query("SELECT * FROM metadata_snapshots WHERE artist LIKE '%' || :query || '%' OR title LIKE '%' || :query || '%' ORDER BY timestamp DESC")
    fun search(query: String): Flow<List<MetadataSnapshot>>
}
