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

import android.content.Context;

import com.alibaba.fastjson.JSONObject;
import com.tofly.ghrq_route.module.planPointRepair.domain.PlanPointRepair;
import com.tofly.ghrq_route.module.planPointRepair.service.IPointRepairService;
import com.tofly.ghrq_route.module.planPointRepair.service.PointRepairServiceImpl;
import com.tofly.ghrq_route.module.planPointRepair.service.PointRepairServiceImplOffline;
import com.tofly.ghrq_route.module.trouble.domain.TroubleAudioBean;
import com.tofly.ghrq_route.module.trouble.domain.TroublePictureBean;

import java.util.List;

/**
 * Created by Amu on 2017/6/5.
 */

public class PointRepairController {
    /**
     * 是否在綫
     */
    boolean mbOnline;
    /**
     * 上下文
     */
    Context mContext;
    /**
     * GPS接口实现对象
     */
    IPointRepairService repairService;

    public PointRepairController(Context context){
        mbOnline = true;
        mContext = context;
        repairService = new PointRepairServiceImpl(context);
    }

    public PointRepairController(boolean online, Context context){
        mbOnline = online;
        mContext = context;
        repairService = new PointRepairServiceImpl(context);
    }

    private void setSignService(boolean online){
        if (online){
            repairService = new PointRepairServiceImpl(mContext);
        }else {
            repairService = new PointRepairServiceImplOffline(mContext);
        }
    }

    /**
     * 添加设备检修点
     * @param token
     * @param pointRepair  检修点
     * @param repairCallBack
     */
    public void addPointRepair(String token, PlanPointRepair pointRepair, PointRepairCallBack repairCallBack){
        repairService.addPointRepair(token, pointRepair, repairCallBack);
    }

    /**
     * 添加设备检修点
     * @param token
     * @param repairCallBack
     */
    public void getPointRepairList(String token, int pageindex, int pagesize, PointRepairCallBack repairCallBack){
        repairService.getPointRepairList(token, pageindex, pagesize, repairCallBack);
    }

    /**
     * 删除添加的设备检修点
     * @param token
     * @param repairid  检修点的id
     * @param repairCallBack
     */
    public void removePointRepair(String token, String repairid, PointRepairCallBack repairCallBack){
        repairService.removePointRepair(token, repairid, false, repairCallBack);
    }

    /**
     * 更新设备检修点数据
     * @param token
     * @param pointRepair  检修点
     * @param repairCallBack
     */
    public void updatePointRepair(String token, PlanPointRepair pointRepair, PointRepairCallBack repairCallBack){
        repairService.updatePointRepair(token, pointRepair, repairCallBack);
    }

    /**
     * 获取设备检修点信息
     * @param token
     * @param repairCallBack
     */
    public void getPointRepairInfo(String token, String pointid, String plan_id, boolean online, PointRepairCallBack repairCallBack){
        setSignService(online);
        repairService.getPointRepairInfo(token, pointid, plan_id, repairCallBack);
    }

    /**
     *  添加子计划设备检修点
     */
    public void addPointChildRepair(String token, String child_plan_id, PlanPointRepair pointRepair, List<TroublePictureBean> photos, PointRepairCallBack repairCallBack){
        repairService = new PointRepairServiceImpl(mContext);
        repairService.addPointChildRepair(token, child_plan_id ,pointRepair, photos, repairCallBack);
    }

    /**
     *  添加子计划调压设备等检修点
     */
    public void addAdjustPressDeviceChildRepair(Context context, PlanPointRepair pointRepair, List<TroublePictureBean> photos, boolean isUpdate, PointRepairCallBack repairCallBack){
        repairService = new PointRepairServiceImpl(mContext);
        repairService.addAdjustPressDeviceChildRepair(context, pointRepair, photos, isUpdate, repairCallBack);
    }

    /**
     *  添加子计划阀门设备检修点
     */
    public void addCommonDeviceRepairRecord(Context context, PlanPointRepair pointRepair, List<TroublePictureBean> photos, boolean isUpdate, PointRepairCallBack repairCallBack){
        repairService = new PointRepairServiceImpl(mContext);
        repairService.addCommonDeviceRepairRecord(context, pointRepair, photos, isUpdate, repairCallBack);
    }

    /**
     *  获取子计划设备检修点历史列表
     */
    public void getPointChildRepairList(String token, String child_plan_id, PlanPointRepair pointRepair, int pageindex, int pagesize, PointRepairCallBack repairCallBack){
        repairService.getPointChildRepairList(token, child_plan_id, pointRepair, pageindex, pagesize, repairCallBack);
    }

    /**
     *  获取子计划调压设备检修点历史列表
     */
    public void getAdjustDeviceChildRepairList(Context context, String user_id, String plan_id, String point_id, final int pageindex, final int pagesize, final PointRepairCallBack repairCallBack){
        repairService = new PointRepairServiceImpl(mContext);
        repairService.getAdjustDeviceChildRepairList(context, user_id, plan_id, point_id, pageindex, pagesize, repairCallBack);
    }

    /**
     *  获取子计划阀门设备检修点历史列表
     */
    public void getCommonDeviceChildRepairList(Context context, String user_id, String plan_id, String point_id, final int pageindex, final int pagesize, final PointRepairCallBack repairCallBack){
        repairService = new PointRepairServiceImpl(mContext);
        repairService.getCommonDeviceChildRepairList(context, user_id, plan_id, point_id, pageindex, pagesize, repairCallBack);
    }


    /**
     * 删除添加的子计划设备检修点
     * @param token
     * @param repairid  检修点的id
     * @param repairCallBack
     */
    public void removePointChildRepair(String token, String repairid, PointRepairCallBack repairCallBack){
        repairService = new PointRepairServiceImpl(mContext);
        repairService.removePointRepair(token, repairid, true, repairCallBack);
    }

    /**
     * 获取调压设备检修需要录入的参数配置
     */
    public void getAdjustDeviceSettingList(Context context, int pageindex, int pagesize, boolean online,  PointRepairCallBack repairCallBack) {
        setSignService(online);
        repairService.getAdjustDeviceSettingList(context, pageindex, pagesize, repairCallBack);
    }

    /**
     * 获取阀井设备检修需要录入的参数配置
     */
    public void getCommonDeviceSettingList(Context context, int pageindex, int pagesize, boolean online, PointRepairCallBack repairCallBack) {
        setSignService(online);
        repairService.getCommonDeviceSettingList(context, pageindex, pagesize, repairCallBack);
    }

    /**
     * 获取设备检修相关的nfc图文信息
     * @param token
     * @param rfid      nfc设备的rfid标识码
     * @param device_type_id  该巡检计划device_type_id
     * @param repairCallBack
     */
    public void getRepairNFCInfo(String token, String rfid, int device_type_id, PointRepairCallBack repairCallBack){
        repairService = new PointRepairServiceImpl(mContext);
        repairService.getRepairNFCInfo(token, rfid, device_type_id, repairCallBack);
    }

    /**
     *  获取巡检设备类型列表
     */
    public void getRouteDeviceTypeList(Context context, String typeIds, int pageindex, int pagesize, PointRepairCallBack repairCallBack) {
        repairService.getRouteDeviceTypeList(context, typeIds, pageindex, pagesize, repairCallBack);
    }

    /**
     *  获取设备检修参数列表
     */
    public void getDeviceRouteParamList(Context context, String deviceId, int pageindex, int pagesize, PointRepairCallBack repairCallBack) {
        repairService.getDeviceRouteParamList(context, deviceId, pageindex, pagesize, repairCallBack);
    }

    /**
     *  添加子计划设备检修记录
     */
    public void uploadDeviceRouteRecord(Context context, JSONObject jsonObject, List<TroublePictureBean> pictures, List<TroubleAudioBean> audioBeans, boolean isUpdate, PointRepairCallBack repairCallBack) {
        repairService.uploadDeviceRouteRecord(context, jsonObject, pictures, audioBeans, isUpdate, repairCallBack);
    }

    /**
     *  获取子计划设备检修历史列表
     */
    public void getDeviceRouteRecordList(Context context, String plan_id, String point_id, final int pageindex, final int pagesize, final PointRepairCallBack repairCallBack) {
        repairService.getDeviceRouteRecordList(context, plan_id, point_id, pageindex, pagesize, repairCallBack);
    }
}
