package com.example.dtf.dao

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

@Dao
interface CommentDao {
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insert(comment: Comment)

    @Update
    suspend fun update(comment: Comment)

    @Delete
    suspend fun delete(comment: Comment)

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

    @Query("select * from comment where comment.post_id = :postId ORDER BY id DESC")
    fun getByPost(postId: Int) : PagingSource<Int, Comment>

    @Query("delete from comment where post_id = :query")
    fun deleteByQuery(query: String)
}
