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

import android.content.Context;

import com.tofly.ghrq_route.module.OfflineWork.OfflineWorkTool;
import com.tofly.ghrq_route.module.buildManage.BuildExaminesBean;
import com.tofly.ghrq_route.module.buildManage.domain.BuildFileBean;
import com.tofly.ghrq_route.module.buildManage.domain.BuildHandleBean;
import com.tofly.ghrq_route.module.buildManage.domain.BuildManageBean;
import com.tofly.ghrq_route.module.buildManage.domain.BuildManageBeans;
import com.tofly.ghrq_route.module.buildManage.domain.BuildProcessManageBean;
import com.tofly.ghrq_route.module.buildManage.domain.BuildReportBean;
import com.tofly.ghrq_route.module.buildManage.service.BuildManageServiceImpl;
import com.tofly.ghrq_route.module.buildManage.service.BuildManageServiceImplOffline;
import com.tofly.ghrq_route.module.buildManage.service.IBuildManageService;
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/5/22.
 */

public class BuildManageController {

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

    public BuildManageController(Context context) {
        mbOnline = true;
        mContext = context;
        buildManageService = new BuildManageServiceImpl(context);
    }

    public BuildManageController(boolean online, Context context) {
        mbOnline = online;
        mContext = context;
        buildManageService = new BuildManageServiceImpl(context);
    }

    private void setSignService() {
        boolean isOffline = OfflineWorkTool.isOffline();
        if (isOffline) {
            buildManageService = new BuildManageServiceImplOffline(mContext);
        } else {
            buildManageService = new BuildManageServiceImpl(mContext);
        }
    }

    private void setSignService(boolean online) {
        if (online) {
            buildManageService = new BuildManageServiceImpl(mContext);
        } else {
            buildManageService = new BuildManageServiceImplOffline(mContext);
        }
    }

    /**
     * 获取工地监护列表
     *
     * @param pageindex           当前页index
     * @param pagesize            每页数据大小
     * @param buildManageCallback
     */
    public void getBuildManageList(String type, boolean online, int pageindex, int pagesize, BuildManageCallback buildManageCallback) {
        setSignService(online);
        buildManageService.getBuildManageList(type, pageindex, pagesize, buildManageCallback);
    }

    public void getDataList(int type , int pageindex, int pagesize, BuildManageCallback buildManageCallback) {
        buildManageService.getDataList(type,pageindex, pagesize, buildManageCallback);
    }

    public void searchData(String keyWord, int pageindex, int pagesize, BuildManageCallback buildManageCallback) {
        buildManageService.searchData(keyWord,pageindex, pagesize, buildManageCallback);
    }

    public void getBuildDetail(String id, BuildManageCallback buildManageCallback) {
        buildManageService.getBuildDetail(id, buildManageCallback);
    }

    /**
     * 获取工地类型列表
     *
     * @param token
     * @param pageindex           当前页index
     * @param pagesize            每页数据大小
     * @param buildManageCallback
     */
    public void getBuildProjectTypeList(String token, int pageindex, int pagesize, BuildManageCallback buildManageCallback) {
        setSignService();
        buildManageService.getBuildProjectTypeList(token, pageindex, pagesize, buildManageCallback);
    }

    /**
     * 获取工地负责人列表
     *
     * @param buildManageCallback
     */
    public void getManagerList(BuildManageCallback buildManageCallback) {
        // setSignService();
        buildManageService.getManagerList(buildManageCallback);
    }

    /**
     * 获取工地类型列表
     *
     * @param
     */
    public void getBuildType(BuildManageCallback buildManageCallback) {
        setSignService();
        buildManageService.getBuildTye(buildManageCallback);
    }

    /**
     * 获取工地回报列表
     *
     * @param token
     * @param buildid             唯一工地id
     * @param pageindex           当前页index
     * @param pagesize            每页数据大小
     * @param buildManageCallback
     */
    public void getBuildReportList(String token, String buildid, int pageindex, int pagesize, BuildManageCallback buildManageCallback) {
        setSignService();
        buildManageService.getBuildReportList(token, buildid, pageindex, pagesize, buildManageCallback);
    }

    /**
     * 上传工地回报记录
     *
     * @param token
     * @param reportBean 回报记录
     */
    public void uploadBuildReport(String token, String userid, BuildReportBean reportBean, List<TroublePictureBean> photos, List<TroubleAudioBean> audios, BuildManageCallback buildManageCallback) {
        buildManageService = new BuildManageServiceImpl(mContext);
        buildManageService.uploadBuildReport(token, userid, reportBean, photos, audios, buildManageCallback);
    }

    /**
     * 删除工地回报记录
     *
     * @param token
     * @param reportid 回报记录的ID
     */
    public void removeBuildReport(String token, String reportid, BuildManageCallback buildManageCallback) {
        buildManageService = new BuildManageServiceImpl(mContext);
        buildManageService.removeBuildReport(token, reportid, buildManageCallback);
    }

    /**
     * 获取监护申请列表
     *
     * @param token
     * @param buildid             唯一工地id
     * @param pageindex           当前页index
     * @param pagesize            每页数据大小
     * @param buildManageCallback
     */
    public void getBuildHandleList(String token, String buildid, int pageindex, int pagesize, BuildManageCallback buildManageCallback) {
        buildManageService.getBuildHandleList(token, buildid, pageindex, pagesize, buildManageCallback);
    }

    /**
     * 上传工地监护申请
     *
     * @param token
     * @param handleBean 监护申请
     */
    public void uploadBuildHandle(String token, BuildHandleBean handleBean, BuildManageCallback buildManageCallback) {
        buildManageService.uploadBuildHandle(token, handleBean, buildManageCallback);
    }

    /**
     * 删除工地监护申请记录
     *
     * @param token
     * @param handleid 监护申请记录的ID
     */
    public void removeBuildHandle(String token, String handleid, BuildManageCallback buildManageCallback) {
        buildManageService.removeBuildHandle(token, handleid, buildManageCallback);
    }

    /**
     * 新工地发现
     *
     * @param token
     * @param buildManage 工地信息
     */
    public void addBuildManage(String token, BuildManageBean buildManage, List<TroublePictureBean> photos, List<TroubleAudioBean> audios, List<BuildFileBean> fileBeanList, BuildManageCallback buildManageCallback) {
        buildManageService = new BuildManageServiceImpl(mContext);
        buildManageService.addBuildManage(token, buildManage, photos, audios, fileBeanList, buildManageCallback);
    }

    /**
     * 过程管理
     *
     * @param buildManage 工地信息
     */
    public void addBuildProcessManage(BuildProcessManageBean buildManage, List<TroublePictureBean> photos, List<TroubleAudioBean> audios, List<BuildFileBean> fileBeanList, BuildManageCallback buildManageCallback) {
        buildManageService = new BuildManageServiceImpl(mContext);
        buildManageService.addBuildProcessManage(buildManage, photos, audios, fileBeanList, buildManageCallback);
    }

    /**
     * 更新工地监护状态和停留时间
     */
    public void updateBuildLog(BuildManageBean buildManageBean, BuildManageCallback buildManageCallback) {
        buildManageService = new BuildManageServiceImpl(mContext);
        buildManageService.updateBuildLog(buildManageBean, buildManageCallback);
    }

    /**
     * 获取工地监护列表
     *
     * @param token
     * @param buildManageCallback
     */
    public void getBuildLogList(String token, BuildManageCallback buildManageCallback) {
        buildManageService = new BuildManageServiceImpl(mContext);
        buildManageService.getBuildLogList(token, buildManageCallback);
    }

    /**
     * 工地工单派工
     *
     * @param buildManageBean
     * @param buildManageCallback
     */
    public void getBuildDispatch(BuildManageBeans buildManageBean, BuildManageCallback buildManageCallback) {
        buildManageService = new BuildManageServiceImpl(mContext);
        buildManageService.getBuildDispatch(buildManageBean, buildManageCallback);
    }

    /**
     * 工地工单审核

     * @param buildManageCallback
     */
    public void getBuildExamine(BuildExaminesBean examinesBean, List<BuildFileBean> data, BuildManageCallback buildManageCallback) {
        buildManageService = new BuildManageServiceImpl(mContext);
        buildManageService.getBuildExamine(examinesBean, data, buildManageCallback);
    }
}
