package com.zyzf.coffeepreorder.database.dao

import androidx.paging.PagingSource
import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.Query
import androidx.room.Update
import com.zyzf.coffeepreorder.database.model.User

@Dao
interface UserDao {
    @Query("select * from user")
    fun getAll(): PagingSource<Int, User>

    @Query("select * from user where login = :login and password = :password")
    suspend fun tryLogin(login: String, password: String): User?

    @Query("select * from user where uid = :uid")
    suspend fun getByUid(uid: Int): User?

    @Insert
    fun insert(user: User): Long

    @Insert
    fun insert(vararg user: User)

    @Update
    fun update(user: User): Int?

    @Delete
    suspend fun delete(user: User)

    @Query("delete from user")
    suspend fun deleteAll()
}