package com.example.lab2;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData;

import java.util.List;

public class PhoneViewModel extends AndroidViewModel {
    private final PhoneRepository repo;
    private final LiveData<List<Phone>> phones;

    public PhoneViewModel(@NonNull Application application) {
        super(application);
        repo = new PhoneRepository(application);
        phones = repo.getAllPhones();
    }

    public LiveData<List<Phone>> getAllPhones() {
        return phones;
    }

    public void deleteAll() {
        repo.deleteAll();
    }

    public void delete(Phone phone) {
        repo.delete(phone);
    }

    public void insert(Phone phone) {
        repo.insert(phone);
    }

    public void update(Phone phone) {
        repo.update(phone);
    }
}
