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

import android.content.Context;

import com.tofly.ghrq_route.module.OfflineWork.OfflineWorkTool;
import com.tofly.ghrq_route.module.buildManage.domain.BuildFileBean;
import com.tofly.ghrq_route.module.rushrepair.domain.RushRepairBean;
import com.tofly.ghrq_route.module.rushrepair.domain.RushRepairBeanList;
import com.tofly.ghrq_route.module.rushrepair.domain.RushRepairExamineList;
import com.tofly.ghrq_route.module.rushrepair.domain.RushRepairProcessBean;
import com.tofly.ghrq_route.module.rushrepair.service.RushRepairServiceImpl;
import com.tofly.ghrq_route.module.rushrepair.service.RushRepairServiceImplOffline;
import com.tofly.ghrq_route.module.rushrepair.service.IRushRepairService;
import com.tofly.ghrq_route.module.trouble.domain.TroubleAudioBean;
import com.tofly.ghrq_route.module.trouble.domain.TroublePictureBean;

import java.util.List;

/**
 * @author YCHK
 */
public class RushRepairController {

    /**
     * 是否在綫
     */
    boolean mbOnline;
    /**
     * 上下文
     */
    Context mContext;
    /**
     * Trouble接口实现对象
     */
    IRushRepairService rushRepairService;

    public RushRepairController(Context context) {
        mbOnline = true;
        mContext = context;
        rushRepairService = new RushRepairServiceImpl(context);
    }

    public RushRepairController(boolean online, Context context) {
        mbOnline = online;
        mContext = context;
        rushRepairService = new RushRepairServiceImpl(context);
    }

    private void setSignService() {
        boolean isOffline = OfflineWorkTool.isOffline();
        if (isOffline) {
            rushRepairService = new RushRepairServiceImplOffline(mContext);
        } else {
            rushRepairService = new RushRepairServiceImpl(mContext);
        }
    }

    private void setSignService(boolean online) {
        if (online) {
            rushRepairService = new RushRepairServiceImpl(mContext);
        } else {
            rushRepairService = new RushRepairServiceImplOffline(mContext);
        }
    }


    public void addBuildJobManage(RushRepairBean buildJobBean, List<TroublePictureBean> photos, List<TroubleAudioBean> audios, List<BuildFileBean> filesList, RushRepairCallback rushRepairCallback) {
        rushRepairService = new RushRepairServiceImpl(mContext);
        rushRepairService.addBuildJobManage(buildJobBean, photos, audios, filesList, rushRepairCallback);
    }

    /**
     * 获取抢维修列表
     *
     * @param pageindex      当前页index
     * @param pagesize       每页数据大小
     * @param repairCallback
     */
    public void getRushRepairList(boolean online, int pageindex, int pagesize, RushRepairCallback repairCallback) {
        setSignService(online);
        rushRepairService.getRushRepairList(pageindex, pagesize, repairCallback);
    }

    public void getDataList(int state,int pageindex, int pagesize, RushRepairCallback repairCallback) {
        rushRepairService.getDataList(state, pageindex, pagesize, repairCallback);
    }

    public void searchData(String keyWord,int pageindex, int pagesize, RushRepairCallback repairCallback) {
        rushRepairService.searchData(keyWord, pageindex, pagesize, repairCallback);
    }

    public void getDataDetail(String id, RushRepairCallback repairCallback) {
        rushRepairService.getDataDetail(id, repairCallback);
    }

    /**
     * 更新抢维修监护状态
     */
    public void updateRushProcessState(RushRepairBean rushRepairBean, RushRepairCallback repairCallback) {
        rushRepairService = new RushRepairServiceImpl(mContext);
        rushRepairService.updateRushProcessState(rushRepairBean, repairCallback);
    }

    /**
     * 获取工地负责人列表
     *
     * @param repairCallback
     */
    public void getManagerList(RushRepairCallback repairCallback) {
        setSignService();
        rushRepairService.getRushrenList(repairCallback);
    }

    /**
     * 抢维修工单派工
     *
     * @param rushRepairBean
     * @param rushRepairCallback
     */
    public void getBuildDispatch(RushRepairBeanList rushRepairBean, RushRepairCallback rushRepairCallback) {
        rushRepairService = new RushRepairServiceImpl(mContext);
        rushRepairService.getRushDispatch(rushRepairBean, rushRepairCallback);
    }

    /**
     * 过程管理
     *
     * @param buildManage 工地信息
     */
    public void addRushProcessManage(RushRepairProcessBean buildManage, List<TroublePictureBean> photos, List<TroubleAudioBean> audios, List<BuildFileBean> fileBeanList, RushRepairCallback buildManageCallback) {
        rushRepairService = new RushRepairServiceImpl(mContext);
        rushRepairService.addRushProcessManage(buildManage, photos, audios, fileBeanList, buildManageCallback);
    }

    /**
     * 抢维修工单审核

     * @param repairCallback
     */
    public void getRushExamine(RushRepairExamineList examinesBean, List<BuildFileBean> data, RushRepairCallback repairCallback) {
        rushRepairService = new RushRepairServiceImpl(mContext);
        rushRepairService.getRushExamine(examinesBean, data, repairCallback);
    }

}
