package com.example.shawarma.data.interfaces.dao

import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy.Companion.ABORT
import androidx.room.Query
import androidx.room.Update
import com.example.shawarma.data.models.UserModel
import kotlinx.coroutines.flow.Flow

@Dao
interface UserDao {
    @Insert(onConflict = ABORT)
    suspend fun insert(user: UserModel)
    @Update
    suspend fun update(user: UserModel)
    @Delete
    suspend fun delete(user: UserModel)
    @Query("select * from users order by user_login collate nocase asc")
    fun getAll(): Flow<List<UserModel>>
    @Query("select * from users where id = :id")
    fun getById(id: Int): Flow<UserModel>
    @Query("select * from users where user_login = :login and user_password = :password limit 1")
    fun login(login: String, password: String) : Flow<UserModel?>
}