package com.tofly.ghrq_route.module.rushrepair.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.domain.BuildFileBean;
import com.tofly.ghrq_route.module.rushrepair.controller.RushRepairCallback;
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.sqlite.DBDaoHelper;
import com.tofly.ghrq_route.module.trouble.domain.TroubleAudioBean;
import com.tofly.ghrq_route.module.trouble.domain.TroublePictureBean;

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

public class RushRepairServiceImplOffline implements IRushRepairService {

    private Context context;
    private DBDaoHelper dbDaoHelper;

    public RushRepairServiceImplOffline(Context context) {
        this.context = context;
        dbDaoHelper = DBDaoHelper.getInstance();
    }

    @Override
    public void addBuildJobManage(RushRepairBean buildManage, List<TroublePictureBean> photos, List<TroubleAudioBean> audios, List<BuildFileBean> filesList, RushRepairCallback rushRepairCallback) {

    }

    @Override
    public void getRushRepairList(int pageindex, int pagesize, RushRepairCallback repairCallback) {
        String userId = BaseApp.getInstance().getLoginUser().getUserid();
        int total = 0;
        List<RushRepairBean> rushRepairBeans = dbDaoHelper.getRushRepair("2");
        List<RushRepairBean> rushRepairBeans1 = new ArrayList<>();
        if (rushRepairBeans != null) {
            total = rushRepairBeans.size();
        }
        if (rushRepairBeans != null && rushRepairBeans.size() > 0) {
            for (RushRepairBean rushRepairBean : rushRepairBeans) {
                String rush = rushRepairBean.getRushRepairResponsible();
                String rushs = rushRepairBean.getRushRepairPersons();
                if (!TextUtils.isEmpty(rush)) {
                    if (!TextUtils.isEmpty(rushs)) {
                        if (rush.equals(userId) || rushs.contains(userId)) {
                            rushRepairBeans1.add(rushRepairBean);
                        }
                    } else {
                        if (rush.equals(userId)) {
                            rushRepairBeans1.add(rushRepairBean);
                        }
                    }
                }
            }
        }
        repairCallback.onRepairList(true, URLResponseCode.ErrorCode.SUCCESS_OFFLINE, "", rushRepairBeans1, total);
    }

    @Override
    public void getDataList(int state, int pageindex, int pagesize, RushRepairCallback repairCallback) {

    }

    @Override
    public void searchData(String keyWord, int pageindex, int pagesize, RushRepairCallback repairCallback) {

    }

    @Override
    public void getDataDetail(String id, RushRepairCallback rushRepairCallback) {

    }

    @Override
    public void addRushProcessManage(RushRepairProcessBean buildManage, List<TroublePictureBean> photos, List<TroubleAudioBean> audios, List<BuildFileBean> fileBeanList, RushRepairCallback repairCallback) {

    }

    @Override
    public void updateRushProcessState(RushRepairBean repairBean, RushRepairCallback repairCallback) {

    }

    @Override
    public void getRushrenList(RushRepairCallback repairCallback) {

    }

    @Override
    public void getRushDispatch(RushRepairBeanList rushRepairBean, RushRepairCallback repairCallback) {

    }

    @Override
    public void getRushExamine(RushRepairExamineList examinesBean, List<BuildFileBean> data, RushRepairCallback buildManageCallback) {

    }
}
