package io.nexilis.service.data.viewmodels

import androidx.lifecycle.LiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import io.nexilis.service.data.entities.Message
import io.nexilis.service.data.repositories.MessageRepository
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class MessageViewModel @Inject constructor(private val repository: MessageRepository) :
    ViewModel() {

    val all: LiveData<List<Message>> = repository.all

    fun get(id: String) : LiveData<Message> {
        return repository.get(id)
    }

    fun getOpposite(pin: String) : LiveData<List<Message>> {
        return repository.getOpposite(pin)
    }

    fun insert(entity: Message) = viewModelScope.launch(Dispatchers.IO) {
        repository.insert(entity)
    }

    fun send(entity: Message) = viewModelScope.launch(Dispatchers.IO) {
        repository.send(entity)
    }

}