package com.example.timert.data.viewModel

import android.app.Application
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.LiveData
import androidx.lifecycle.viewModelScope
import com.example.timert.com.example.timert.data.database.AppDatabase
import com.example.timert.com.example.timert.data.entity.Workout
import com.example.timert.data.repository.WorkoutRepository
import kotlinx.coroutines.launch

class WorkoutViewModel(application: Application):AndroidViewModel(application){
    private val repository: WorkoutRepository
    val allWorkouts: LiveData<List<Workout>>

    init{
        val workoutDao = AppDatabase.getDatabase(application).workoutDao()
        repository = WorkoutRepository(workoutDao)
        allWorkouts = repository.allWorkout
    }
    fun insert(workout: Workout) = viewModelScope.launch {
        repository.insert(workout)
    }

    fun deleteWorkoutById(id: Int) = viewModelScope.launch {
        repository.deleteWorkoutById(id)
    }
}