package com.example.myapplication.database.dao;

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.Query
import com.example.myapplication.database.entities.User
import com.example.myapplication.database.entities.UserProductCart
import com.example.myapplication.database.entities.UserWithCartProduct
import kotlinx.coroutines.flow.Flow

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

    @Query("select * from users where users.userId = :id")
    fun getById(id: Int): User

    @Query("select * from users where users.login = :login and users.password = :password")
    fun getByAuth(login: String, password: String): User?

    @Query("delete from userproductcart where userproductcart.userId == :userId and userproductcart.productId == :productId")
    suspend fun deleteCartProduct(userId: Int, productId: Int)

    @Insert
    suspend fun insert(user: User)

    @Query("select * from users where users.userId = :id")
    fun getUserProductCartById(id: Int): UserWithCartProduct

    @Insert
    suspend fun addProductCart(userProduct: UserProductCart)
}