package com.radiola.data.local.dao

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

@Dao
interface RecordingDao {

    @Query("SELECT * FROM recordings ORDER BY startTime DESC")
    fun getAll(): Flow<List<RecordingEntity>>

    @Insert
    suspend fun insert(recording: RecordingEntity)

    @Query("DELETE FROM recordings WHERE id = :id")
    suspend fun deleteById(id: Long)

    @Query("UPDATE recordings SET endTime = :endTime, duration = :duration WHERE id = :id")
    suspend fun updateEndTime(id: Long, endTime: Long, duration: Long)

    @Query("UPDATE recordings SET markers = :markers WHERE id = :id")
    suspend fun updateMarkers(id: Long, markers: String)

    @Query("SELECT * FROM recordings WHERE id = :id")
    suspend fun getById(id: Long): RecordingEntity?
}
