package com.example.timert.data.dao

import androidx.lifecycle.LiveData
import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Transaction
import com.example.timert.data.entity.Exercise


@Dao
interface ExerciseDao {

    @Transaction
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insert(exercise: Exercise)

    @Query("SELECT * FROM exercise_table")
    fun getExercise(): LiveData<List<Exercise>>


    @Query("DELETE FROM exercise_table WHERE id = :id")
    suspend fun deleteById(id: Int)

    @Query("UPDATE exercise_table SET trainingId = :newTrainingId WHERE trainingId = 0")
    suspend fun updateExercisesWithTrainingId(newTrainingId: Int)

    @Query("SELECT * FROM exercise_table WHERE trainingId = :trainingId")
    fun getExercisesByTrainingId(trainingId: Int): LiveData<List<Exercise>>
}