package com.example.dtf.repositories.online

import com.example.dtf.api.ServerService
import com.example.dtf.db.AppDatabase
import com.example.dtf.models.Like
import com.example.dtf.repositories.ILikeRepository
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import javax.inject.Inject

class RestLikeRepository @Inject constructor(
    private val appDatabase: AppDatabase,
    private val serverService: ServerService
) : ILikeRepository {
    override suspend fun insert(like: Like) {
        serverService.likePost(like.postId)
    }

    override suspend fun delete(like: Like) {
        serverService.likePost(like.postId)
    }

    override fun countByPost(postId: Int): Flow<Int> {
        return flow { emit(serverService.getPostLikes(postId)) }
    }

    override fun isLikedByUser(userId: Int, postId: Int): Flow<Boolean> {
        return flow { emit(serverService.postIsLiked(postId)) }
    }
}