// Path: app/src/main/java/com/tylersuehr/cleanarchitecture/data/Injector.java
// public final class Injector {
//     public static PersonRepository providePeopleRepo(Context appCtx) {
//         return PersonRepository.getInstance(new LocalPersonRepository(
//                 DatabaseClient.getInstance(appCtx), new PersonMapper()
//         ));
//     }
// }
// 
// Path: app/src/main/java/com/tylersuehr/cleanarchitecture/data/repositories/people/IPersonRepository.java
// public interface IPersonRepository {
//     /**
//      * Creates a new person in the repository.
//      * @param person {@link Person}
//      * @throws Exception if create fails
//      */
//     void createPerson(Person person) throws Exception;
// 
//     /**
//      * Deletes a person in the repository. Leave null to delete all
//      * people in the repository.
//      * @param person {@link Person}
//      *
//      * @throws Exception if deletion fails
//      */
//     void deletePerson(@Nullable Person person) throws Exception;
// 
//     /**
//      * Finds all people in the repository.
//      * @param callback {@link Callbacks.IList}
//      */
//     void findAllPeople(Callbacks.IList<Person> callback);
// 
//     /**
//      * Finds a person in the repository using their profile ID.
//      * @param personId Person's profile ID
//      * @param callback {@link Callbacks.ISingle}
//      */
//     void findPersonById(String personId, Callbacks.ISingle<Person> callback);
// }
// 
// Path: app/src/main/java/com/tylersuehr/cleanarchitecture/domain/people/AllPeopleTask.java
// public class AllPeopleTask extends UseCase<Object, List<Person>> {
//     private IPersonRepository personRepo;
// 
// 
//     public AllPeopleTask(IPersonRepository personRepo) {
//         this.personRepo = personRepo;
//     }
// 
//     @Override
//     protected void onExecute() {
//         this.personRepo.findAllPeople(new Callbacks.IList<Person>() {
//             @Override
//             public void onListLoaded(List<Person> people) {
//                 pass(people);
//             }
// 
//             @Override
//             public void onNotAvailable(Exception ex) {
//                 fail(ex);
//             }
//         });
//     }
// }
// 
// Path: app/src/main/java/com/tylersuehr/cleanarchitecture/domain/people/DeleteAllPeopleTask.java
// public class DeleteAllPeopleTask extends UseCase<Object, Object> {
//     private final IPersonRepository personRepo;
// 
// 
//     public DeleteAllPeopleTask(IPersonRepository personRepo) {
//         this.personRepo = personRepo;
//     }
// 
//     @Override
//     protected void onExecute() {
//         try {
//             this.personRepo.deletePerson(null);
//             pass(null);
//         } catch (Exception ex) {
//             fail(ex);
//         }
//     }
// }
// 
// Path: app/src/main/java/com/tylersuehr/cleanarchitecture/domain/people/CreatePersonTask.java
// public class CreatePersonTask extends UseCase<CreatePersonTask.Request, Person> {
//     private final IPersonRepository personRepo;
// 
// 
//     public CreatePersonTask(IPersonRepository personRepo) {
//         this.personRepo = personRepo;
//     }
// 
//     @Override
//     protected void onExecute() {
//         try {
//             final Request request = getRequest();
// 
//             // Create the person model
//             Person person = new Person();
//             person.setId(UUID.randomUUID().toString());
//             person.setFirstName(request.first);
//             person.setLastName(request.last);
//             person.setImage(request.image);
//             person.setAge(request.age);
// 
//             // Save person in the repository
//             this.personRepo.createPerson(person);
// 
//             // Callback with the valid model
//             pass(person);
//         } catch (Exception ex) {
//             fail(ex);
//         }
//     }
// 
//     public static final class Request {
//         private final String first;
//         private final String last;
//         private final String image;
//         private final int age;
// 
//         public Request(String first, String last, String image, int age) {
//             this.first = first;
//             this.last = last;
//             this.image = image;
//             this.age = age;
//         }
//     }
// }


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import com.tylersuehr.cleanarchitecture.R;
import com.tylersuehr.cleanarchitecture.data.Injector;
import com.tylersuehr.cleanarchitecture.data.repositories.people.IPersonRepository;
import com.tylersuehr.cleanarchitecture.domain.people.AllPeopleTask;
import com.tylersuehr.cleanarchitecture.domain.people.DeleteAllPeopleTask;
import com.tylersuehr.cleanarchitecture.domain.people.CreatePersonTask;
package com.tylersuehr.cleanarchitecture.ui.people;

/**
 * Copyright 2017 Tyler Suehr
 *
 * @author Tyler Suehr
 * @version 1.0
 */
public class PeopleActivity extends AppCompatActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_people);

        // Setup toolbar
        Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        // Show the people fragment
        IPersonRepository personRepo = Injector.providePeopleRepo(getApplicationContext());
        getSupportFragmentManager()
                .beginTransaction()
                .replace(R.id.body, PeopleFragment.create(
                        new PeoplePresenter(
                                new AllPeopleTask(personRepo),
// Path: app/src/main/java/com/tylersuehr/cleanarchitecture/data/Injector.java
// public final class Injector {
//     public static PersonRepository providePeopleRepo(Context appCtx) {
//         return PersonRepository.getInstance(new LocalPersonRepository(
//                 DatabaseClient.getInstance(appCtx), new PersonMapper()
//         ));
//     }
// }
// 
// Path: app/src/main/java/com/tylersuehr/cleanarchitecture/data/repositories/people/IPersonRepository.java
// public interface IPersonRepository {
//     /**
//      * Creates a new person in the repository.
//      * @param person {@link Person}
//      * @throws Exception if create fails
//      */
//     void createPerson(Person person) throws Exception;
// 
//     /**
//      * Deletes a person in the repository. Leave null to delete all
//      * people in the repository.
//      * @param person {@link Person}
//      *
//      * @throws Exception if deletion fails
//      */
//     void deletePerson(@Nullable Person person) throws Exception;
// 
//     /**
//      * Finds all people in the repository.
//      * @param callback {@link Callbacks.IList}
//      */
//     void findAllPeople(Callbacks.IList<Person> callback);
// 
//     /**
//      * Finds a person in the repository using their profile ID.
//      * @param personId Person's profile ID
//      * @param callback {@link Callbacks.ISingle}
//      */
//     void findPersonById(String personId, Callbacks.ISingle<Person> callback);
// }
// 
// Path: app/src/main/java/com/tylersuehr/cleanarchitecture/domain/people/AllPeopleTask.java
// public class AllPeopleTask extends UseCase<Object, List<Person>> {
//     private IPersonRepository personRepo;
// 
// 
//     public AllPeopleTask(IPersonRepository personRepo) {
//         this.personRepo = personRepo;
//     }
// 
//     @Override
//     protected void onExecute() {
//         this.personRepo.findAllPeople(new Callbacks.IList<Person>() {
//             @Override
//             public void onListLoaded(List<Person> people) {
//                 pass(people);
//             }
// 
//             @Override
//             public void onNotAvailable(Exception ex) {
//                 fail(ex);
//             }
//         });
//     }
// }
// 
// Path: app/src/main/java/com/tylersuehr/cleanarchitecture/domain/people/DeleteAllPeopleTask.java
// public class DeleteAllPeopleTask extends UseCase<Object, Object> {
//     private final IPersonRepository personRepo;
// 
// 
//     public DeleteAllPeopleTask(IPersonRepository personRepo) {
//         this.personRepo = personRepo;
//     }
// 
//     @Override
//     protected void onExecute() {
//         try {
//             this.personRepo.deletePerson(null);
//             pass(null);
//         } catch (Exception ex) {
//             fail(ex);
//         }
//     }
// }
// 
// Path: app/src/main/java/com/tylersuehr/cleanarchitecture/domain/people/CreatePersonTask.java
// public class CreatePersonTask extends UseCase<CreatePersonTask.Request, Person> {
//     private final IPersonRepository personRepo;
// 
// 
//     public CreatePersonTask(IPersonRepository personRepo) {
//         this.personRepo = personRepo;
//     }
// 
//     @Override
//     protected void onExecute() {
//         try {
//             final Request request = getRequest();
// 
//             // Create the person model
//             Person person = new Person();
//             person.setId(UUID.randomUUID().toString());
//             person.setFirstName(request.first);
//             person.setLastName(request.last);
//             person.setImage(request.image);
//             person.setAge(request.age);
// 
//             // Save person in the repository
//             this.personRepo.createPerson(person);
// 
//             // Callback with the valid model
//             pass(person);
//         } catch (Exception ex) {
//             fail(ex);
//         }
//     }
// 
//     public static final class Request {
//         private final String first;
//         private final String last;
//         private final String image;
//         private final int age;
// 
//         public Request(String first, String last, String image, int age) {
//             this.first = first;
//             this.last = last;
//             this.image = image;
//             this.age = age;
//         }
//     }
// }


// Path: app/src/main/java/com/tylersuehr/cleanarchitecture/ui/people/PeopleActivity.java
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import com.tylersuehr.cleanarchitecture.R;
import com.tylersuehr.cleanarchitecture.data.Injector;
import com.tylersuehr.cleanarchitecture.data.repositories.people.IPersonRepository;
import com.tylersuehr.cleanarchitecture.domain.people.AllPeopleTask;
import com.tylersuehr.cleanarchitecture.domain.people.DeleteAllPeopleTask;
import com.tylersuehr.cleanarchitecture.domain.people.CreatePersonTask;

package com.tylersuehr.cleanarchitecture.ui.people;

/**
 * Copyright 2017 Tyler Suehr
 *
 * @author Tyler Suehr
 * @version 1.0
 */
public class PeopleActivity extends AppCompatActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_people);

        // Setup toolbar
        Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        // Show the people fragment
        IPersonRepository personRepo = Injector.providePeopleRepo(getApplicationContext());
        getSupportFragmentManager()
                .beginTransaction()
                .replace(R.id.body, PeopleFragment.create(
                        new PeoplePresenter(
                                new AllPeopleTask(personRepo),
                                new CreatePersonTask(personRepo),