package com.sheep.gamegroup.presenter;

import com.alibaba.fastjson.JSONObject;
import com.sheep.gamegroup.model.api.ApiService;
import com.sheep.gamegroup.model.entity.BaseMessage;
import com.sheep.gamegroup.model.util.SheepSubscriber;
import com.sheep.jiuyan.samllsheep.SheepApp;

import javax.inject.Inject;

import retrofit2.http.Query;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;


/**
 * Created by ljy on 2018/4/2.
 */

public class TaskDetailPresenter implements TaskDetailContract.Presenter {
    private ApiService apiService;
    private TaskDetailContract.View view;

    @Inject
    public TaskDetailPresenter(ApiService apiService, TaskDetailContract.View view) {
        this.apiService = apiService;
        this.view = view;
    }

    @Override
    public void taskStatus( int id, String screenshots,String remark, String package_name, String status, String device, String unique_identification) {
        (unique_identification == null ? apiService.taskStatus(id, screenshots, remark, package_name, status, device) : apiService.taskStatus(id, screenshots, remark, package_name, status, device, unique_identification))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
                    @Override
                    public void onError(BaseMessage baseMessage) {
                        view.taskStatusFaile(baseMessage);
                    }

                    @Override
                    public void onNext(BaseMessage baseMessage) {
                        view.taskStatusSuccess(baseMessage);
                    }
                });
    }

    @Override
    public void taskDesc(int taskid) {
        apiService.taskDesc(taskid)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
                    @Override
                    public void onError(BaseMessage baseMessage) {
                        view.taskDescFaile(baseMessage);
                    }

                    @Override
                    public void onNext(BaseMessage baseMessage) {
                        view.taskDescSuccess(baseMessage);
                    }
                });
    }
}
