package tr.dhee.abox.demo.ui.switchcontrol;

import androidx.lifecycle.ViewModel;
import androidx.lifecycle.ViewModelProvider;
import androidx.annotation.NonNull;

import tr.dhee.abox.demo.data.SwitchDataSource;
import tr.dhee.abox.demo.data.SwitchRepository;

/**
 * ViewModel provider factory to instantiate SwitchViewModel.
 */
public class SwitchViewModelFactory implements ViewModelProvider.Factory {

    @NonNull
    @Override
    @SuppressWarnings("unchecked")
    public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
        if (modelClass.isAssignableFrom(SwitchViewModel.class)) {
            return (T) new SwitchViewModel(SwitchRepository.getInstance(new SwitchDataSource()));
        } else {
            throw new IllegalArgumentException("Unknown ViewModel class");
        }
    }
}
