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

import android.content.Context;
import android.text.TextUtils;

import com.tofly.ghrq_route.base.BaseApp;
import com.tofly.ghrq_route.base.URLResponseCode;
import com.tofly.ghrq_route.module.buildManage.BuildExaminesBean;
import com.tofly.ghrq_route.module.buildManage.controller.BuildManageCallback;
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.BuildProjectTypeBean;
import com.tofly.ghrq_route.module.buildManage.domain.BuildReportBean;
import com.tofly.ghrq_route.module.buildManage.domain.BuildTypeBean;
import com.tofly.ghrq_route.module.sqlite.DBDaoHelper;
import com.tofly.ghrq_route.module.trouble.domain.TroubleAudioBean;
import com.tofly.ghrq_route.module.trouble.domain.TroubleBean;
import com.tofly.ghrq_route.module.trouble.domain.TroublePictureBean;

import java.util.ArrayList;
import java.util.List;

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

public class BuildManageServiceImplOffline implements IBuildManageService {
    private Context mContext;

    private DBDaoHelper dbDaoHelper;

    public BuildManageServiceImplOffline(Context context) {
        mContext = context;
        dbDaoHelper = DBDaoHelper.getInstance();
    }

    @Override
    public void getBuildManageList(final String constructionState, final int pageindex, final int pagesize, final BuildManageCallback buildManageCallback) {
        int total = 0;
        String userid = BaseApp.getInstance().getLoginUser().getUserid();
        List<BuildManageBean> buildManages1 = new ArrayList<>();
        List<BuildManageBean> buildManages = dbDaoHelper.getBuildManages(constructionState);
        switch (constructionState) {
            case "2":
            case "4":
                for (BuildManageBean buildManageBean : buildManages) {
                    String person = buildManageBean.getConstructionPerson();
                    if (!TextUtils.isEmpty(person) && person.equals(userid)) {
                        buildManages1.add(buildManageBean);
                    }
                }
                break;
        }
        if (buildManages != null) {
            total = buildManages.size();
        }
        buildManageCallback.onGetBuildManageList(true, URLResponseCode.ErrorCode.SUCCESS_OFFLINE, "", buildManages1, total);
    }

    @Override
    public void getDataList(int constructionState, int pageindex, int pagesize, BuildManageCallback buildManageCallback) {

    }

    @Override
    public void searchData(String keyWord, int pageindex, int pagesize, BuildManageCallback buildManageCallback) {

    }

    @Override
    public void getBuildDetail(String id, BuildManageCallback buildManageCallback) {

    }

    @Override
    public void getBuildProjectTypeList(final String token, final int pageindex, final int pagesize, final BuildManageCallback buildManageCallback) {
        int total = 0;
        List<BuildProjectTypeBean> buildTypes = dbDaoHelper.getBuildProjectTypeList();
        if (buildTypes != null) {
            total = buildTypes.size();
        }
        buildManageCallback.onGetBuildProjectTypeList(true, URLResponseCode.ErrorCode.SUCCESS_OFFLINE, "", buildTypes, total);
    }

    @Override
    public void getManagerList(BuildManageCallback buildManageCallback) {
        // List<BuildManagerBean> buildManagerBeanList = dbDaoHelper.getBuildManagerList();
        //  buildManageCallback.onGetManagerList(true, URLResponseCode.ErrorCode.SUCCESS_OFFLINE, "", buildManagerBeanList);
    }

    @Override
    public void getBuildTye(BuildManageCallback buildManageCallback) {
        List<BuildTypeBean> data = new ArrayList<>();
        boolean isSuccess = false;
        String errMsg = "暂无数据";
        int errCode = 1;
        if (dbDaoHelper.getBuildTypeList() != null || dbDaoHelper.getBuildTypeList().size() > 0) {
            data = dbDaoHelper.getBuildTypeList();
            isSuccess = true;
            errCode = 0;
            errMsg = "加载成功";
        }
        buildManageCallback.onGetBuildTypeList(isSuccess, errCode, errMsg, data);
    }

    @Override
    public void getBuildReportList(final String token, final String build_id, final int pageindex, final int pagesize, final BuildManageCallback buildManageCallback) {
        int total = 0;
        List<BuildReportBean> reportList = dbDaoHelper.getBuildReportList(build_id, TroubleBean.SERVER_STATE);
        if (reportList != null) {
            total = reportList.size();
        }
        buildManageCallback.onGetBuildReportList(true, URLResponseCode.ErrorCode.SUCCESS_OFFLINE, "", reportList, total);
    }

    @Override
    public void uploadBuildReport(final String token, final String userid, final BuildReportBean reportBean,
                                  final List<TroublePictureBean> photos, final List<TroubleAudioBean> audios, final BuildManageCallback buildManageCallback) {

    }

    @Override
    public void removeBuildReport(final String token, String reportid, final BuildManageCallback buildManageCallback) {

    }

    @Override
    public void getBuildHandleList(final String token, final String buildid, final int pageindex, final int pagesize, final BuildManageCallback buildManageCallback) {

    }

    @Override
    public void uploadBuildHandle(final String token, final BuildHandleBean handleBean, final BuildManageCallback buildManageCallback) {

    }

    @Override
    public void removeBuildHandle(final String token, String handleid, final BuildManageCallback buildManageCallback) {

    }

    @Override
    public void addBuildManage(final String token, final BuildManageBean buildManage, final List<TroublePictureBean> photos,
                               final List<TroubleAudioBean> audios, List<BuildFileBean> fileBeanList, final BuildManageCallback buildManageCallback) {

    }

    @Override
    public void addBuildProcessManage(BuildProcessManageBean buildManage, List<TroublePictureBean> photos, List<TroubleAudioBean> audios, List<BuildFileBean> fileBeanList, BuildManageCallback buildManageCallback) {

    }

    @Override
    public void updateBuildLog(BuildManageBean buildManageBean, final BuildManageCallback buildManageCallback) {

    }

    @Override
    public void getBuildLogList(final String token, final BuildManageCallback buildManageCallback) {

    }

    @Override
    public void getBuildDispatch(BuildManageBeans buildManageBean, BuildManageCallback buildManageCallback) {

    }

    @Override
    public void getBuildExamine(BuildExaminesBean examinesBean, List<BuildFileBean> data, BuildManageCallback buildManageCallback) {

    }
}
