package com.example.pmulabs.room.dao

import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.Query
import androidx.room.Update
import com.example.pmulabs.room.models.Comment
import kotlinx.coroutines.flow.Flow

@Dao
interface CommentDao {
    @Query("select * from comment")
    fun getAll(): Flow<List<Comment>>

    @Query("select COUNT(*) from comment WHERE comment.text!='' AND comment.article_id= :idArticle")
    fun getCountComment(idArticle : Int?) : Int

    @Query("SELECT * FROM comment ORDER BY id DESC LIMIT :limit OFFSET :offset")
    suspend fun getComments(limit: Int, offset: Int): List<Comment>

    @Insert
    suspend fun insert(comment: Comment)

    @Update
    suspend fun update(comment: Comment)

    @Delete
    suspend fun delete(comment: Comment)
}