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.Tag
import kotlinx.coroutines.flow.Flow

@Dao
interface TagDao {
    @Query("select * from tag")
    fun getAll(): Flow<List<Tag>>

    @Query("select * from tag where tag.id = :idTag")
    fun getTagById(idTag: Int): Flow<Tag>

    @Query("select * from tag where tag.title = :nameTag")
    fun getTagByName(nameTag: String): Flow<Tag>

    @Query("SELECT * FROM tag ORDER BY id ASC LIMIT :limit OFFSET :offset")
    suspend fun getTags(limit: Int, offset: Int): List<Tag>

    @Insert
    suspend fun insert(tag: Tag)

    @Update
    suspend fun update(tag: Tag)

    @Delete
    suspend fun delete(tag: Tag)
}