// Path: app/src/main/java/com/sefford/material/sample/common/model/Contact.java
// public class Contact implements Comparable<Contact>, Renderable, RepoElement<Long>, Updateable<Contact> {
// 
//     long id;
//     Uri thumb;
//     Uri photo;
//     String name;
//     List<String> phones = new ArrayList<String>();
//     List<String> emails = new ArrayList<String>();
//     LayoutMode mode = LayoutMode.LIST;
// 
//     @Override
//     public Long getId() {
//         return id;
//     }
// 
//     public void setId(long id) {
//         this.id = id;
//         final Uri contactUri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, id);
//         thumb = Uri.withAppendedPath(contactUri, ContactsContract.Contacts.Photo.CONTENT_DIRECTORY);
//         photo = Uri.withAppendedPath(contactUri, ContactsContract.Contacts.Photo.DISPLAY_PHOTO);
//     }
// 
//     public void setId(Long id) {
//         this.id = id;
//     }
// 
//     public String getName() {
//         return name;
//     }
// 
//     public void setName(String name) {
//         this.name = name;
//     }
// 
//     public List<String> getPhones() {
//         return phones;
//     }
// 
//     public void setPhones(List<String> phones) {
//         this.phones = phones;
//     }
// 
//     public void addPhone(String phone) {
//         this.phones.add(phone);
//     }
// 
//     public List<String> getEmails() {
//         return emails;
//     }
// 
//     public void setEmails(List<String> emails) {
//         this.emails = emails;
//     }
// 
//     public void addEmail(String email) {
//         this.emails.add(email);
//     }
// 
//     public Uri getThumbnail() {
//         return thumb;
//     }
// 
//     public Uri getPhoto() {
//         return photo;
//     }
// 
//     @Override
//     public boolean equals(Object o) {
//         if (this == o) return true;
//         if (o == null || getClass() != o.getClass()) return false;
// 
//         Contact contact = (Contact) o;
// 
//         if (id != contact.id) return false;
// 
//         return true;
//     }
// 
//     @Override
//     public int hashCode() {
//         return (int) (id ^ (id >>> 32));
//     }
// 
//     @Override
//     public int compareTo(Contact another) {
//         return name.compareTo(another.name);
//     }
// 
//     @Override
//     public int getRenderableId() {
//         if (LayoutMode.LIST.equals(mode)) {
//             return R.layout.listitem_contact;
//         } else {
//             return R.layout.griditem_contact;
//         }
//     }
// 
//     @Override
//     public Contact update(Contact other) {
//         return this;
//     }
// 
//     public void setLayoutMode(LayoutMode layoutMode) {
//         this.mode = layoutMode;
//     }
// 
//     public enum LayoutMode {
//         LIST,
//         GRID,
//         STAGGER
//     }
// }
// 
// Path: app/src/main/java/com/sefford/material/sample/contacts/details/delegates/GetContactDelegate.java
// public class GetContactDelegate implements CacheDelegate<GetContactResponse, GetContactError> {
// 
//     static final String NAME = "GetContact(%d)";
// 
//     final Repository<Long, Contact> repository;
//     final long id;
// 
//     public GetContactDelegate(Repository<Long, Contact> repository, long id) {
//         this.repository = repository;
//         this.id = id;
//     }
// 
//     @Override
//     public boolean isCacheValid() {
//         return true;
//     }
// 
//     @Override
//     public GetContactResponse execute() throws Exception {
//         final Contact contact = repository.get(id);
//         final ContactData phones = new ContactData(contact.getPhones(), R.drawable.ic_phone_black, R.layout.listitem_phone);
//         final ContactData mails = new ContactData(contact.getEmails(), R.drawable.ic_email_black, R.layout.listitem_mail);
//         return new GetContactResponse(contact, phones, mails);
//     }
// 
//     @Override
//     public GetContactError composeErrorResponse(Exception error) {
//         return new GetContactError();
//     }
// 
//     @Override
//     public String getInteractorName() {
//         return String.format(NAME, id);
//     }
// }


import com.sefford.kor.common.interfaces.Loggable;
import com.sefford.kor.common.interfaces.Postable;
import com.sefford.kor.interactors.CacheInteractor;
import com.sefford.kor.interactors.Interactor;
import com.sefford.kor.interactors.StandaloneInteractor;
import com.sefford.kor.repositories.interfaces.Repository;
import com.sefford.material.sample.common.model.Contact;
import com.sefford.material.sample.contacts.details.delegates.GetContactDelegate;
import javax.inject.Inject;
import java.util.concurrent.ThreadPoolExecutor;
/*
 * Copyright (C) 2015 Saúl Díaz
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.sefford.material.sample.contacts.details.interactors;



/**
 * Retrieves a a {@link Contact Contact}.
 */
public class GetContact extends StandaloneInteractor<Long> {

    final Repository<Long, Contact> repository;

    /**
     * Creates a new instance of the Standalone Interactor.
     *
     * @param log        Logging facilities
     * @param executor   Execution element
     * @param repository
     */
    @Inject
    public GetContact(Loggable log, ThreadPoolExecutor executor, Repository<Long, Contact> repository) {
        super(log, executor);
        this.repository = repository;
    }

    @Override
    protected Interactor instantiateInteractor(Postable bus, Long id) {
// Path: app/src/main/java/com/sefford/material/sample/common/model/Contact.java
// public class Contact implements Comparable<Contact>, Renderable, RepoElement<Long>, Updateable<Contact> {
// 
//     long id;
//     Uri thumb;
//     Uri photo;
//     String name;
//     List<String> phones = new ArrayList<String>();
//     List<String> emails = new ArrayList<String>();
//     LayoutMode mode = LayoutMode.LIST;
// 
//     @Override
//     public Long getId() {
//         return id;
//     }
// 
//     public void setId(long id) {
//         this.id = id;
//         final Uri contactUri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, id);
//         thumb = Uri.withAppendedPath(contactUri, ContactsContract.Contacts.Photo.CONTENT_DIRECTORY);
//         photo = Uri.withAppendedPath(contactUri, ContactsContract.Contacts.Photo.DISPLAY_PHOTO);
//     }
// 
//     public void setId(Long id) {
//         this.id = id;
//     }
// 
//     public String getName() {
//         return name;
//     }
// 
//     public void setName(String name) {
//         this.name = name;
//     }
// 
//     public List<String> getPhones() {
//         return phones;
//     }
// 
//     public void setPhones(List<String> phones) {
//         this.phones = phones;
//     }
// 
//     public void addPhone(String phone) {
//         this.phones.add(phone);
//     }
// 
//     public List<String> getEmails() {
//         return emails;
//     }
// 
//     public void setEmails(List<String> emails) {
//         this.emails = emails;
//     }
// 
//     public void addEmail(String email) {
//         this.emails.add(email);
//     }
// 
//     public Uri getThumbnail() {
//         return thumb;
//     }
// 
//     public Uri getPhoto() {
//         return photo;
//     }
// 
//     @Override
//     public boolean equals(Object o) {
//         if (this == o) return true;
//         if (o == null || getClass() != o.getClass()) return false;
// 
//         Contact contact = (Contact) o;
// 
//         if (id != contact.id) return false;
// 
//         return true;
//     }
// 
//     @Override
//     public int hashCode() {
//         return (int) (id ^ (id >>> 32));
//     }
// 
//     @Override
//     public int compareTo(Contact another) {
//         return name.compareTo(another.name);
//     }
// 
//     @Override
//     public int getRenderableId() {
//         if (LayoutMode.LIST.equals(mode)) {
//             return R.layout.listitem_contact;
//         } else {
//             return R.layout.griditem_contact;
//         }
//     }
// 
//     @Override
//     public Contact update(Contact other) {
//         return this;
//     }
// 
//     public void setLayoutMode(LayoutMode layoutMode) {
//         this.mode = layoutMode;
//     }
// 
//     public enum LayoutMode {
//         LIST,
//         GRID,
//         STAGGER
//     }
// }
// 
// Path: app/src/main/java/com/sefford/material/sample/contacts/details/delegates/GetContactDelegate.java
// public class GetContactDelegate implements CacheDelegate<GetContactResponse, GetContactError> {
// 
//     static final String NAME = "GetContact(%d)";
// 
//     final Repository<Long, Contact> repository;
//     final long id;
// 
//     public GetContactDelegate(Repository<Long, Contact> repository, long id) {
//         this.repository = repository;
//         this.id = id;
//     }
// 
//     @Override
//     public boolean isCacheValid() {
//         return true;
//     }
// 
//     @Override
//     public GetContactResponse execute() throws Exception {
//         final Contact contact = repository.get(id);
//         final ContactData phones = new ContactData(contact.getPhones(), R.drawable.ic_phone_black, R.layout.listitem_phone);
//         final ContactData mails = new ContactData(contact.getEmails(), R.drawable.ic_email_black, R.layout.listitem_mail);
//         return new GetContactResponse(contact, phones, mails);
//     }
// 
//     @Override
//     public GetContactError composeErrorResponse(Exception error) {
//         return new GetContactError();
//     }
// 
//     @Override
//     public String getInteractorName() {
//         return String.format(NAME, id);
//     }
// }


// Path: app/src/main/java/com/sefford/material/sample/contacts/details/interactors/GetContact.java
import com.sefford.kor.common.interfaces.Loggable;
import com.sefford.kor.common.interfaces.Postable;
import com.sefford.kor.interactors.CacheInteractor;
import com.sefford.kor.interactors.Interactor;
import com.sefford.kor.interactors.StandaloneInteractor;
import com.sefford.kor.repositories.interfaces.Repository;
import com.sefford.material.sample.common.model.Contact;
import com.sefford.material.sample.contacts.details.delegates.GetContactDelegate;
import javax.inject.Inject;
import java.util.concurrent.ThreadPoolExecutor;

/*
 * Copyright (C) 2015 Saúl Díaz
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.sefford.material.sample.contacts.details.interactors;



/**
 * Retrieves a a {@link Contact Contact}.
 */
public class GetContact extends StandaloneInteractor<Long> {

    final Repository<Long, Contact> repository;

    /**
     * Creates a new instance of the Standalone Interactor.
     *
     * @param log        Logging facilities
     * @param executor   Execution element
     * @param repository
     */
    @Inject
    public GetContact(Loggable log, ThreadPoolExecutor executor, Repository<Long, Contact> repository) {
        super(log, executor);
        this.repository = repository;
    }

    @Override
    protected Interactor instantiateInteractor(Postable bus, Long id) {
        return new CacheInteractor(bus, log, new GetContactDelegate(repository, id));