package com.develop.common.data_repo.db.dao

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import com.develop.common.data_repo.db.entity.*

@Dao
interface UserInfoDao {

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun updateUserInfo(userInfo: UserInfo)

    @Query("select * from user_info")
    fun queryUserInfo(): List<UserInfo>

    @Query("delete from user_info")
    fun deleteAllUserInfo()

    @Query("select * from user_info where userId =:userId")
    fun queryUserInfoByUserId(userId: Long): UserInfo?

    @Query("select * from user_history_recipes where userId =:userId")
    fun queryHistoryRecipes(userId: Long): List<UserHistoryRecipes>

    @Query("select * from user_favorite_recipes where userId =:userId")
    fun queryFavoriteRecipes(userId: Long): List<UserFavoriteRecipes>

    @Insert
    fun insertHistoryRecipe(historyRecipes: UserHistoryRecipes)

    @Insert
    fun insertFavoriteRecipe(favoriteRecipes: UserFavoriteRecipes)

    @Query("Delete from user_history_recipes where historyRecipesId =:historyRecipeId and userId = :userId")
    fun removeHistoryRecipe(userId: Long, historyRecipeId: String)

    @Query("Delete from user_favorite_recipes where favoriteRecipesId =:favoriteRecipeId and userId = :userId")
    fun removeFavoriteRecipe(userId: Long, favoriteRecipeId: String)

    @Query("select * from user_tag where userId = :userId and recipesId =:recipesId")
    fun queryUserTag(userId: Long, recipesId: String): UserTag?

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun updateUserTag(userTag: UserTag)

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun insertOnlineRecipe(onLineRecipes: UserOnLineRecipes)

    @Query("Delete from user_online_recipes where onLineRecipesId =:onLineRecipesId and userId = :userId")
    fun removeOnlineRecipe(userId: Long, onLineRecipesId: String)

    @Query("select * from user_online_recipes")
    fun queryUserOnLineRecipesIds(): List<UserOnLineRecipes>


    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun insertUserRecipeStepRemark(userRecipeStepRemark: UserRecipeStepRemark)

    @Query("select * from user_recipe_step_remark where userId = :userId and recipeNumber =:recipeNumber and  stepNumber=:stepNumber")
    fun queryUserRecipeStepRemark(
        userId: Long,
        recipeNumber: String,
        stepNumber: String
    ): UserRecipeStepRemark?


    @Query("select * from user_favorite_recipes where favoriteRecipesId =:recipeId and userId =:userId")
    fun queryFavoriteRecipes(userId: Long, recipeId: String): List<UserFavoriteRecipes>

}