package com.zyzf.coffeepreorder.database.dao

import androidx.paging.PagingSource
import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.Query
import androidx.room.Update
import com.zyzf.coffeepreorder.database.model.Coffee

@Dao
interface CoffeeDao {
    @Query("select * from coffee order by name collate nocase asc")
    fun getAllCoffees(): PagingSource<Int, Coffee>

    @Query("select coffee.uid, name, cost, ingredients from coffee where coffee.uid = :uid")
    suspend fun getByUid(uid: Int): Coffee?

    @Insert
    fun insert(coffee: Coffee): Long

    @Insert
    suspend fun insert(vararg coffee: Coffee)

    @Update
    fun update(coffee: Coffee): Int

    @Delete
    suspend fun delete(coffee: Coffee)

    @Query("delete from coffee")
    suspend fun deleteAll()
}