package com.offline.music.task.player.db.bean

import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Update

@Dao
interface LocalAudioDao {

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insertAudioFile(barcode: LocalAudio)

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insertAudioFiles(localAudios: List<LocalAudio>)

    @Query("SELECT * FROM LocalAudio")
    suspend fun getAllAudioFile(): List<LocalAudio>

    @Delete
    suspend fun deleteAudioFile(barcode: LocalAudio)

    @Query("DELETE FROM LocalAudio")
    suspend fun deleteAllAudioFile()

    @Update
    suspend fun updateAudioFile(localAudioFile: LocalAudio)

    @Query("SELECT * FROM LocalAudio WHERE name = :path LIMIT 1")
    suspend fun getAudioFileByPath(path: String): LocalAudio?

    @Query("SELECT * FROM LocalAudio WHERE selected = 1")
    suspend fun getAudioBySelected(): List<LocalAudio>

    @Query("update LocalAudio set collect = 0")
    suspend fun deleteAllCollect()

    @Query("select * from LocalAudio where collect = :collect ")
    suspend fun getCollectData(collect: Boolean = true): List<LocalAudio>
}
