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.Article
import com.example.pmulabs.room.models.Comment
import com.example.pmulabs.room.models.Tag
import com.example.pmulabs.room.models.User
import kotlinx.coroutines.flow.Flow

@Dao
interface UserDao {
    @Query("select * from user")
    fun getAll(): Flow<List<User>>

    @Query("select * from user where user.id = :idUser")
    fun getUserById(idUser: Int?): Flow<User>

    @Query("select * from comment WHERE comment.text!='' AND comment.user_id= :idUser")
    fun getUserComms(idUser: Int): Flow<List<Comment>>

    @Query("select * from article WHERE article.text!='' AND article.user_id= :idUser")
    fun getUserArticles(idUser: Int): Flow<List<Article>>

    @Query("select * from tag WHERE tag.title!='' AND tag.user_id= :idUser")
    fun getUserTags(idUser: Int): Flow<List<Tag>>

    @Insert
    suspend fun insert(user: User)

    @Update
    suspend fun update(user: User)

    @Delete
    suspend fun delete(user: User)
}