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 rx.android.schedulers.AndroidSchedulers;
import rx.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(JSONObject jsonObject) {
        apiService.taskStatus(jsonObject.getInteger("id"),jsonObject.getString("screenshots"),
                jsonObject.getString("remark"),jsonObject.getString("package_name"),jsonObject.getString("status"))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.mContext) {
                    @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.mContext) {
                    @Override
                    public void onError(BaseMessage baseMessage) {
                        view.taskDescFaile(baseMessage);
                    }

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