package io.nexilis.service.data.daos

import androidx.lifecycle.LiveData
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Update
import io.nexilis.service.data.entities.*

@Dao
interface BuddyDao {

    @Query("select * from Buddy where type = '0'")
    fun getAll(): LiveData<List<Buddy>>

    @Query("select * from Buddy where type = '1'")
    fun getMe(): LiveData<Buddy>

    @Query("select * from Buddy where f_pin = :pin")
    fun getBuddy(pin: String): LiveData<Buddy>

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insert(entity: Buddy)

    @Update
    suspend fun update(entity: Buddy)

    @Query("update Buddy set image_id = :image where f_pin = :pin")
    suspend fun updateImage(image: String, pin: String)

    @Query("update Buddy set image_id = :image where type = '1'")
    suspend fun updateImageMe(image: String)

    @Query("delete from Buddy")
    suspend fun deleteAll()

    @Query("delete from Buddy where f_pin = :pin")
    suspend fun delete(pin: String)

    @Query("delete from Buddy where type = '1'")
    suspend fun deleteMe()

}