package com.example.dtf.dao

import androidx.paging.PagingSource
import androidx.room.*
import com.example.dtf.models.*
import kotlinx.coroutines.flow.Flow

@Dao
interface CategoryDao {
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insert(category: Category)

    @Update
    suspend fun update(category: Category)

    @Delete
    suspend fun delete(category: Category)

    @Query("select * from category")
    fun getAll() : PagingSource<Int, Category>

    @Query("select * from category")
    fun getAllCached() : Flow<List<Category>>

    @Query("select * from category where category.id = :id")
    fun getById(id: Int) : Flow<Category>

    @Query("select * from category limit 1")
    fun getFirst() : Flow<Category>
}
