// Path: app/src/main/java/com/jonathanpetitfrere/mvvm/repository/UserRepository.java
// @Singleton
// public class UserRepository {
// 
//     @Inject
//     UserApi userApi;
// 
//     @Inject
//     UserDao userDao;
// 
//     @Inject
//     UserMapper mapper;
// 
//     @Inject
//     Transformers transformers;
// 
//     @Inject
//     UserRepository() {}
// 
//     public LiveData<User> getUser(String email) {
//         MutableLiveData<User> liveData = new MutableLiveData<>();
// 
//         userDao.loadUser(email)
//                 .compose(transformers.applySchedulersToFlowable())
//                 .subscribe(liveData::setValue, Timber::d);
// 
//         userApi.getUser(email)
//                 .compose(transformers.applySchedulersToFlowable())
//                 .map(mapper::toEntity)
//                 .subscribe(userDao::saveUser, Timber::d);
// 
//         return liveData;
//     }
// 
//     public LiveData<List<User>> getUsers() {
//         MutableLiveData<List<User>> liveData = new MutableLiveData<>();
// 
//         userDao.loadUsers()
//                 .compose(transformers.applySchedulersToFlowable())
//                 .subscribe(liveData::setValue, Timber::d);
// 
//         userApi.getUsers()
//                 .compose(transformers.applySchedulersToFlowable())
//                 .flatMapIterable(users -> users)
//                 .map(mapper::toEntity)
//                 .subscribe(userDao::saveUser, Timber::d);
// 
//         return liveData;
//     }
// 
//     public LiveData<Boolean> saveUser(User user) {
//         MutableLiveData<Boolean> liveData = new MutableLiveData<>();
// 
//         Completable.fromAction(() -> userDao.saveUser(user))
//                 .compose(transformers.applySchedulersToCompletable())
//                 .subscribe(() -> liveData.setValue(true), throwable -> {
//                     Timber.d(throwable);
//                     liveData.setValue(false);
//                 });
// 
// 
//         return liveData;
//     }
// }
// 
// Path: app/src/main/java/com/jonathanpetitfrere/mvvm/repository/persistence/entity/User.java
// @Entity
// public class User {
// 
//     @PrimaryKey
//     private String email;
// 
//     @ColumnInfo(name = "first_name")
//     private String firstName;
// 
//     @ColumnInfo(name = "last_name")
//     private String lastName;
// 
//     public User(String email, String firstName, String lastName) {
//         this.email = email;
//         this.firstName = firstName;
//         this.lastName = lastName;
//     }
// 
//     public String getEmail() {
//         return email;
//     }
// 
//     public String getFirstName() {
//         return firstName;
//     }
// 
//     public String getLastName() {
//         return lastName;
//     }
// 
//     @Override
//     public boolean equals(Object object) {
//         if (this == object) return true;
//         if (object == null || getClass() != object.getClass()) return false;
// 
//         User user = (User) object;
// 
//         if (email != null ? !email.equals(user.email) : user.email != null) return false;
//         if (firstName != null ? !firstName.equals(user.firstName) : user.firstName != null)
//             return false;
//         return lastName != null ? lastName.equals(user.lastName) : user.lastName == null;
// 
//     }
// 
//     @Override
//     public int hashCode() {
//         int result = email != null ? email.hashCode() : 0;
//         result = 31 * result + (firstName != null ? firstName.hashCode() : 0);
//         result = 31 * result + (lastName != null ? lastName.hashCode() : 0);
//         return result;
//     }
// }
// 
// Path: app/src/main/java/com/jonathanpetitfrere/mvvm/ui/base/BaseAndroidViewModel.java
// public abstract class BaseAndroidViewModel extends AndroidViewModel {
// 
//     public BaseAndroidViewModel(Application application) {
//         super(application);
//     }
// 
//     protected MvvmApplication getMvvmApplication() {
//         return (MvvmApplication) getApplication();
//     }
// }


import android.app.Application;
import android.arch.lifecycle.LiveData;
import android.arch.lifecycle.MutableLiveData;
import com.jonathanpetitfrere.mvvm.repository.UserRepository;
import com.jonathanpetitfrere.mvvm.repository.persistence.entity.User;
import com.jonathanpetitfrere.mvvm.ui.base.BaseAndroidViewModel;
import java.util.List;
import javax.inject.Inject;
package com.jonathanpetitfrere.mvvm.ui.main;





/**
 * @author jpetit
 */

public class MainViewModel extends BaseAndroidViewModel {

    @Inject
    UserRepository userRepository;

    private MutableLiveData<String> emailLiveData = new MutableLiveData<>();

    private MutableLiveData<String> firstNameLiveData = new MutableLiveData<>();

    private MutableLiveData<String> lastNameLiveData = new MutableLiveData<>();

    private MutableLiveData<Boolean> validInputLiveData = new MutableLiveData<>();

    public MainViewModel(Application application) {
        super(application);
        getMvvmApplication().getComponent().inject(this);
    }

    public LiveData<Boolean> createUser() {
        User user = new User(emailLiveData.getValue(), firstNameLiveData.getValue(), lastNameLiveData.getValue());
        return userRepository.saveUser(user);
    }

// Path: app/src/main/java/com/jonathanpetitfrere/mvvm/repository/UserRepository.java
// @Singleton
// public class UserRepository {
// 
//     @Inject
//     UserApi userApi;
// 
//     @Inject
//     UserDao userDao;
// 
//     @Inject
//     UserMapper mapper;
// 
//     @Inject
//     Transformers transformers;
// 
//     @Inject
//     UserRepository() {}
// 
//     public LiveData<User> getUser(String email) {
//         MutableLiveData<User> liveData = new MutableLiveData<>();
// 
//         userDao.loadUser(email)
//                 .compose(transformers.applySchedulersToFlowable())
//                 .subscribe(liveData::setValue, Timber::d);
// 
//         userApi.getUser(email)
//                 .compose(transformers.applySchedulersToFlowable())
//                 .map(mapper::toEntity)
//                 .subscribe(userDao::saveUser, Timber::d);
// 
//         return liveData;
//     }
// 
//     public LiveData<List<User>> getUsers() {
//         MutableLiveData<List<User>> liveData = new MutableLiveData<>();
// 
//         userDao.loadUsers()
//                 .compose(transformers.applySchedulersToFlowable())
//                 .subscribe(liveData::setValue, Timber::d);
// 
//         userApi.getUsers()
//                 .compose(transformers.applySchedulersToFlowable())
//                 .flatMapIterable(users -> users)
//                 .map(mapper::toEntity)
//                 .subscribe(userDao::saveUser, Timber::d);
// 
//         return liveData;
//     }
// 
//     public LiveData<Boolean> saveUser(User user) {
//         MutableLiveData<Boolean> liveData = new MutableLiveData<>();
// 
//         Completable.fromAction(() -> userDao.saveUser(user))
//                 .compose(transformers.applySchedulersToCompletable())
//                 .subscribe(() -> liveData.setValue(true), throwable -> {
//                     Timber.d(throwable);
//                     liveData.setValue(false);
//                 });
// 
// 
//         return liveData;
//     }
// }
// 
// Path: app/src/main/java/com/jonathanpetitfrere/mvvm/repository/persistence/entity/User.java
// @Entity
// public class User {
// 
//     @PrimaryKey
//     private String email;
// 
//     @ColumnInfo(name = "first_name")
//     private String firstName;
// 
//     @ColumnInfo(name = "last_name")
//     private String lastName;
// 
//     public User(String email, String firstName, String lastName) {
//         this.email = email;
//         this.firstName = firstName;
//         this.lastName = lastName;
//     }
// 
//     public String getEmail() {
//         return email;
//     }
// 
//     public String getFirstName() {
//         return firstName;
//     }
// 
//     public String getLastName() {
//         return lastName;
//     }
// 
//     @Override
//     public boolean equals(Object object) {
//         if (this == object) return true;
//         if (object == null || getClass() != object.getClass()) return false;
// 
//         User user = (User) object;
// 
//         if (email != null ? !email.equals(user.email) : user.email != null) return false;
//         if (firstName != null ? !firstName.equals(user.firstName) : user.firstName != null)
//             return false;
//         return lastName != null ? lastName.equals(user.lastName) : user.lastName == null;
// 
//     }
// 
//     @Override
//     public int hashCode() {
//         int result = email != null ? email.hashCode() : 0;
//         result = 31 * result + (firstName != null ? firstName.hashCode() : 0);
//         result = 31 * result + (lastName != null ? lastName.hashCode() : 0);
//         return result;
//     }
// }
// 
// Path: app/src/main/java/com/jonathanpetitfrere/mvvm/ui/base/BaseAndroidViewModel.java
// public abstract class BaseAndroidViewModel extends AndroidViewModel {
// 
//     public BaseAndroidViewModel(Application application) {
//         super(application);
//     }
// 
//     protected MvvmApplication getMvvmApplication() {
//         return (MvvmApplication) getApplication();
//     }
// }


// Path: app/src/main/java/com/jonathanpetitfrere/mvvm/ui/main/MainViewModel.java
import android.app.Application;
import android.arch.lifecycle.LiveData;
import android.arch.lifecycle.MutableLiveData;
import com.jonathanpetitfrere.mvvm.repository.UserRepository;
import com.jonathanpetitfrere.mvvm.repository.persistence.entity.User;
import com.jonathanpetitfrere.mvvm.ui.base.BaseAndroidViewModel;
import java.util.List;
import javax.inject.Inject;

package com.jonathanpetitfrere.mvvm.ui.main;





/**
 * @author jpetit
 */

public class MainViewModel extends BaseAndroidViewModel {

    @Inject
    UserRepository userRepository;

    private MutableLiveData<String> emailLiveData = new MutableLiveData<>();

    private MutableLiveData<String> firstNameLiveData = new MutableLiveData<>();

    private MutableLiveData<String> lastNameLiveData = new MutableLiveData<>();

    private MutableLiveData<Boolean> validInputLiveData = new MutableLiveData<>();

    public MainViewModel(Application application) {
        super(application);
        getMvvmApplication().getComponent().inject(this);
    }

    public LiveData<Boolean> createUser() {
        User user = new User(emailLiveData.getValue(), firstNameLiveData.getValue(), lastNameLiveData.getValue());
        return userRepository.saveUser(user);
    }

    public LiveData<User> getUser(String email) {