package com.tofly.ghrq_route.module.incident.controller;

import android.content.Context;

import com.tofly.ghrq_route.base.BaseApp;
import com.tofly.ghrq_route.base.URLResponseCode;
import com.tofly.ghrq_route.module.incident.domain.CarUploadBean;
import com.tofly.ghrq_route.module.incident.domain.DeviceUploadBean;
import com.tofly.ghrq_route.module.incident.service.MonitorServiceImpl;
import com.tofly.ghrq_route.module.user.domain.UserBean;

import java.util.List;

public class MonitorController {
  MonitorServiceImpl service;

    public MonitorController() {
        service = new MonitorServiceImpl();
    }

    /**
     * 获取实时监控设备状态信息列表
     */
    public void getDeviceUploadList(Context context, String departId, final MonitorContact.GetDeviceUploadListCallback callback){
        UserBean userBean = BaseApp.getInstance().getLoginUser();
        String departmentId = departId;
        if (departmentId == null) {
            if (userBean != null)
                departmentId = userBean.getDepartmentId();
        }
        if (departmentId == null || departmentId.isEmpty()){
            int errcode = URLResponseCode.ErrorCode.GET_USER_FAILED;
            String errMsg = URLResponseCode.ErrorCode.getErrorMessage(errcode);
            callback.onError(errcode, errMsg);
            return;
        }

        final int pageindex = 1;
        final int pagesize = 1000;
        service.getDeviceUploadList(context, departmentId, pageindex, pagesize, new MonitorCallback(){
            @Override
            public void onGetDeviceUploadList(boolean isSuccess, int errorCode, String errMsg, List<DeviceUploadBean> deviceList, int total) {
                super.onGetDeviceUploadList(isSuccess, errorCode, errMsg, deviceList, total);
                if (isSuccess){
                    callback.getDataList(deviceList, total);
                }else {
                    callback.onError(errorCode, errMsg);
                }
            }
        });
    }

    /**
     * 获取实时监控车辆状态信息列表
     */
    public void getCarUploadList(Context context, final MonitorContact.GetCarUploadListCallback callback){
        final int pageindex = 1;
        final int pagesize = 1000;
        service.getCarUploadList(context, pageindex, pagesize, new MonitorCallback(){
            @Override
            public void onGetCarUploadList(boolean isSuccess, int errorCode, String errMsg, List<CarUploadBean> carList, int total) {
                super.onGetCarUploadList(isSuccess, errorCode, errMsg, carList, total);
                if (isSuccess){
                    callback.getDataList(carList, total);
                }else {
                    callback.onError(errorCode, errMsg);
                }
            }
        });
    }
}
