package com.example.dtf.dao

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

@Dao
interface LikeDao {
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insert(like: Like)

    @Delete
    suspend fun delete(like: Like)

    @Query("SELECT COUNT(*) FROM likes WHERE post_id = :postId")
    fun countByPost(postId: Int) : Flow<Int>

    @Query("SELECT COUNT(*) = 1 FROM likes WHERE post_id = :postId AND user_id = :userId")
    fun isLikedByUser(userId: Int, postId: Int) : Flow<Boolean>
}