// Path: domain/src/main/java/com/cesarvaliente/permissionsample/domain/action/ListContactsAction.java
// public interface ListContactsAction {
// 
//     interface DataCallback {
//         void onDataLoaded(List<ContactEntity> contactEntityList);
//     }
// 
//     void getPhoneBookContacts(DataCallback dataCallback);
// }
// 
// Path: domain/src/main/java/com/cesarvaliente/permissionsample/domain/action/ListContactsAction.java
// interface DataCallback {
//     void onDataLoaded(List<ContactEntity> contactEntityList);
// }
// 
// Path: domain/src/main/java/com/cesarvaliente/permissionsample/domain/entity/ContactEntity.java
// public class ContactEntity {
// 
//     private String id;
//     private String name;
//     private String email;
//     private String phone;
// 
//     public ContactEntity(String id, String name, String phone) {
//         this.id = id;
//         this.name = name;
//         this.phone = phone;
//     }
// 
//     public String getId() {
//         return id;
//     }
// 
//     public void setId(String id) {
//         this.id = id;
//     }
// 
//     public String getName() {
//         return name;
//     }
// 
//     public void setName(String name) {
//         this.name = name;
//     }
// 
//     public String getEmail() {
//         return email;
//     }
// 
//     public void setEmail(String email) {
//         this.email = email;
//     }
// 
//     public String getPhone() {
//         return phone;
//     }
// 
//     public void setPhone(String phone) {
//         this.phone = phone;
//     }
// 
//     @Override
//     public String toString() {
//         StringBuilder builder = new StringBuilder("ContactEntity --> ");
//         builder.append(name).append(" - ").append(email).append(" - ").append(phone);
//         return builder.toString();
//     }
// }
// 
// Path: domain/src/main/java/com/cesarvaliente/permissionsample/domain/executor/PostExecutionThread.java
// public interface PostExecutionThread {
//     /**
//      * Causes the {@link Runnable} to be added to the message queue of the Main UI Thread
//      * of the application.
//      *
//      * @param runnable {@link Runnable} to be executed.
//      */
//     void post(Runnable runnable);
// }
// 
// Path: domain/src/main/java/com/cesarvaliente/permissionsample/domain/executor/ThreadExecutor.java
// public interface ThreadExecutor {
// 
//     void execute(Runnable runnable);
// }
// 
// Path: domain/src/main/java/com/cesarvaliente/permissionsample/domain/usecase/ListContactsUseCase.java
// public interface ListContactsUseCase extends UseCase {
// 
//     interface UiCallbacks {
//         void onComplete(List<ContactEntity> contactEntity);
// 
//         void onError(String error);
//     }
// 
//     void execute(UiCallbacks uiCallbacks);
// 
// }


import java.util.List;
import com.cesarvaliente.permissionsample.domain.action.ListContactsAction;
import com.cesarvaliente.permissionsample.domain.action.ListContactsAction.DataCallback;
import com.cesarvaliente.permissionsample.domain.entity.ContactEntity;
import com.cesarvaliente.permissionsample.domain.executor.PostExecutionThread;
import com.cesarvaliente.permissionsample.domain.executor.ThreadExecutor;
import com.cesarvaliente.permissionsample.domain.usecase.ListContactsUseCase;
/**
 * Copyright (C) 2015 Cesar Valiente based in the code of Fernando Cejas
 * https://github.com/android10/Android-CleanArchitecture
 *
 * 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.cesarvaliente.permissionsample.domain.usecase.impl;



/**
 * Created by Cesar on 19/09/15.
 */
public class ListContactsUseCaseImpl implements ListContactsUseCase {

    private ListContactsAction listContactsAction;
    private ThreadExecutor threadExecutor;
    private PostExecutionThread postExecutionThread;
    private UiCallbacks uiUiCallbacks;
    private DataCallback dataCallback;

    public ListContactsUseCaseImpl(ListContactsAction listContactsAction, ThreadExecutor threadExecutor,
                                   PostExecutionThread postExecutionThread) {
        this.listContactsAction = listContactsAction;
        this.threadExecutor = threadExecutor;
        this.postExecutionThread = postExecutionThread;
    }

    @Override
    public void execute(final UiCallbacks uiCallbacks) {
        this.uiUiCallbacks = uiCallbacks;

        dataCallback = new DataCallback() {
            @Override
            public void onDataLoaded(final List<ContactEntity> contactEntityList) {
                notifyUiOnSuccess(contactEntityList);
            }
        };
        threadExecutor.execute(this);
    }

    @Override
    public void run() {
        listContactsAction.getPhoneBookContacts(dataCallback);
    }

// Path: domain/src/main/java/com/cesarvaliente/permissionsample/domain/action/ListContactsAction.java
// public interface ListContactsAction {
// 
//     interface DataCallback {
//         void onDataLoaded(List<ContactEntity> contactEntityList);
//     }
// 
//     void getPhoneBookContacts(DataCallback dataCallback);
// }
// 
// Path: domain/src/main/java/com/cesarvaliente/permissionsample/domain/action/ListContactsAction.java
// interface DataCallback {
//     void onDataLoaded(List<ContactEntity> contactEntityList);
// }
// 
// Path: domain/src/main/java/com/cesarvaliente/permissionsample/domain/entity/ContactEntity.java
// public class ContactEntity {
// 
//     private String id;
//     private String name;
//     private String email;
//     private String phone;
// 
//     public ContactEntity(String id, String name, String phone) {
//         this.id = id;
//         this.name = name;
//         this.phone = phone;
//     }
// 
//     public String getId() {
//         return id;
//     }
// 
//     public void setId(String id) {
//         this.id = id;
//     }
// 
//     public String getName() {
//         return name;
//     }
// 
//     public void setName(String name) {
//         this.name = name;
//     }
// 
//     public String getEmail() {
//         return email;
//     }
// 
//     public void setEmail(String email) {
//         this.email = email;
//     }
// 
//     public String getPhone() {
//         return phone;
//     }
// 
//     public void setPhone(String phone) {
//         this.phone = phone;
//     }
// 
//     @Override
//     public String toString() {
//         StringBuilder builder = new StringBuilder("ContactEntity --> ");
//         builder.append(name).append(" - ").append(email).append(" - ").append(phone);
//         return builder.toString();
//     }
// }
// 
// Path: domain/src/main/java/com/cesarvaliente/permissionsample/domain/executor/PostExecutionThread.java
// public interface PostExecutionThread {
//     /**
//      * Causes the {@link Runnable} to be added to the message queue of the Main UI Thread
//      * of the application.
//      *
//      * @param runnable {@link Runnable} to be executed.
//      */
//     void post(Runnable runnable);
// }
// 
// Path: domain/src/main/java/com/cesarvaliente/permissionsample/domain/executor/ThreadExecutor.java
// public interface ThreadExecutor {
// 
//     void execute(Runnable runnable);
// }
// 
// Path: domain/src/main/java/com/cesarvaliente/permissionsample/domain/usecase/ListContactsUseCase.java
// public interface ListContactsUseCase extends UseCase {
// 
//     interface UiCallbacks {
//         void onComplete(List<ContactEntity> contactEntity);
// 
//         void onError(String error);
//     }
// 
//     void execute(UiCallbacks uiCallbacks);
// 
// }


// Path: domain/src/main/java/com/cesarvaliente/permissionsample/domain/usecase/impl/ListContactsUseCaseImpl.java
import java.util.List;
import com.cesarvaliente.permissionsample.domain.action.ListContactsAction;
import com.cesarvaliente.permissionsample.domain.action.ListContactsAction.DataCallback;
import com.cesarvaliente.permissionsample.domain.entity.ContactEntity;
import com.cesarvaliente.permissionsample.domain.executor.PostExecutionThread;
import com.cesarvaliente.permissionsample.domain.executor.ThreadExecutor;
import com.cesarvaliente.permissionsample.domain.usecase.ListContactsUseCase;

/**
 * Copyright (C) 2015 Cesar Valiente based in the code of Fernando Cejas
 * https://github.com/android10/Android-CleanArchitecture
 *
 * 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.cesarvaliente.permissionsample.domain.usecase.impl;



/**
 * Created by Cesar on 19/09/15.
 */
public class ListContactsUseCaseImpl implements ListContactsUseCase {

    private ListContactsAction listContactsAction;
    private ThreadExecutor threadExecutor;
    private PostExecutionThread postExecutionThread;
    private UiCallbacks uiUiCallbacks;
    private DataCallback dataCallback;

    public ListContactsUseCaseImpl(ListContactsAction listContactsAction, ThreadExecutor threadExecutor,
                                   PostExecutionThread postExecutionThread) {
        this.listContactsAction = listContactsAction;
        this.threadExecutor = threadExecutor;
        this.postExecutionThread = postExecutionThread;
    }

    @Override
    public void execute(final UiCallbacks uiCallbacks) {
        this.uiUiCallbacks = uiCallbacks;

        dataCallback = new DataCallback() {
            @Override
            public void onDataLoaded(final List<ContactEntity> contactEntityList) {
                notifyUiOnSuccess(contactEntityList);
            }
        };
        threadExecutor.execute(this);
    }

    @Override
    public void run() {
        listContactsAction.getPhoneBookContacts(dataCallback);
    }

    private void notifyUiOnSuccess(final List<ContactEntity> contactEntityList) {