package com.develop.food.base.repo.db.dao

import androidx.room.*
import com.develop.food.base.repo.CURRENT_USER_ID
import com.develop.food.base.repo.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 order by id desc")
    fun queryHistoryRecipes(userId: Long): List<UserHistoryRecipes>

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

    @Query("delete from user_info where userId =:userId")
    fun deleteUserInfoByUserId(userId: Long)

    @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 where userId=:userId")
    fun queryUserOnLineRecipesIds(userId: Long = CURRENT_USER_ID): 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>


    @Query("delete  from user_history_recipes where userId =:userId")
    fun deleteAllHistoryRecipes(userId: Long)


    @Query("Delete from user_online_recipes where userId = :userId")
    fun removeAllOnlineRecipe(userId: Long)


    @Query("Delete from user_history_recipes where userId = :userId")
    fun removeAllHistoryRecipe(userId: Long)


    @Query("Delete from user_favorite_recipes where userId = :userId")
    fun removeAllFavouriteRecipe(userId: Long)

    @Query("Delete from user_tag where userId = :userId")
    fun removeAllOnUserTag(userId: Long)

}