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.Training
import com.example.timert.data.trainingWithExercise


@Dao
interface TrainingDao {

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insertTraining(training: Training) : Long

    @Query("SELECT * FROM Training WHERE id = :trainingId")
    fun getTrainingWithExercise(trainingId: Int): LiveData<trainingWithExercise>

    @Delete
    fun deleteTraining(training: Training)

    @Query("SELECT * FROM training")
    fun getAllTrainings(): LiveData<List<Training>>

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

    @Query("SELECT * FROM training WHERE id = :trainingId")
    fun getTrainingWithExercises(trainingId: Int): LiveData<trainingWithExercise>
    @Transaction
    @Query("SELECT * FROM training")
    fun getAllTrainingsWithExercises(): LiveData<List<trainingWithExercise>>

    @Transaction
    @Query("SELECT * FROM training")
    fun getTrainingsWithExercises(): LiveData<List<trainingWithExercise>>

    @Query("SELECT * FROM training WHERE id = :id")
    fun getTrainingById(id: Int): LiveData<Training>
}
