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

import android.content.Context;

import com.tofly.ghrq_route.base.URLResponseCode;
import com.tofly.ghrq_route.module.plan.controller.PlanCallBack;
import com.tofly.ghrq_route.module.plan.domain.OfflinePathBean;
import com.tofly.ghrq_route.module.plan.domain.PlanBean;
import com.tofly.ghrq_route.module.sqlite.DBDaoHelper;

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

/**
 * Created by Amu on 2017/3/18.
 */

public class PlanServiceImplOffline implements IPlanService {
    private Context mContext;

    private DBDaoHelper dbDaoHelper;

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

    @Override
    public void getPlanList(final String token, final String userid, final int state, final int period, final int planmode, final int pageindex, final int pagesize, final PlanCallBack planCallBack) {
        int total = 0;
        List<PlanBean> planBeans = null;
        if (state == PlanBean.SELECT_STATE_ING){
            List<Integer> planStates = new ArrayList<>();
            planStates.add(PlanBean.PlAN_STATE_TYPE.PLAN_STATE_ING);
            planStates.add(PlanBean.PlAN_STATE_TYPE.PLAN_STATE_ING_TRANSFER_APPLY);
            planBeans = dbDaoHelper.getPlanList(userid, planmode, planStates);

        }else if (state == PlanBean.SELECT_STATE_TODAY){
            planBeans = dbDaoHelper.getPlanList(userid, planmode);
        }
        if (planBeans != null) {
            total = planBeans.size();
        }
        planCallBack.onGetPlanList(true, URLResponseCode.ErrorCode.SUCCESS_OFFLINE, "", planBeans, total);
    }

    @Override
    public void getPlanListMobile(Context context, String userid, int state, int period, int planmode, int pageindex, int pagesize, PlanCallBack planCallBack) {
        int total = 0;
        List<PlanBean> planBeans = null;
        if (state == PlanBean.SELECT_STATE_ING){
            List<Integer> planStates = new ArrayList<>();
            planStates.add(PlanBean.PlAN_STATE_TYPE.PLAN_STATE_ING);
            planStates.add(PlanBean.PlAN_STATE_TYPE.PLAN_STATE_ING_TRANSFER_APPLY);
            planBeans = dbDaoHelper.getPlanList(userid, planmode, planStates);
        }else if (state == PlanBean.SELECT_STATE_TODAY){
            planBeans = dbDaoHelper.getPlanList(userid, planmode);
        }
        if (planBeans != null) {
            total = planBeans.size();
        }
        planCallBack.onGetPlanList(true, URLResponseCode.ErrorCode.SUCCESS_OFFLINE, "", planBeans, total);
    }

    @Override
    public void getPlanInfo(final String token, String plan_id, final PlanCallBack planCallBack) {
        PlanBean planBean = dbDaoHelper.getPlan(plan_id);
        planCallBack.onGetPlanInfo(true, URLResponseCode.ErrorCode.SUCCESS_OFFLINE, "", planBean);
    }

    @Override
    public void getTodayPlanCount(Context context, final String userid, final int plan_mode, final List<String> localPlanIds, final PlanCallBack planCallBack) {

    }

    @Override
    public void transferPlanApply(Context context, final List<String> childplanids, final String note, final PlanCallBack planCallBack) {

    }

    @Override
    public void getPlanPointList(final String token, String planid, final int pageindex, final int pagesize, final PlanCallBack planCallBack) {

    }

    @Override
    public void getChildPlanList(final String token, final String planid, final int pageindex, final int pagesize, final PlanCallBack planCallBack) {

    }

    @Override
    public void getChildPlanPointList(final String token, String childid, final int pageindex, final int pagesize, final PlanCallBack planCallBack) {

    }

    @Override
    public void getChildPlanInfo(final String token, String childplanid, final PlanCallBack planCallBack) {

    }

    @Override
    public void getOfflinePathList(final String token, final String userid, final String planIds, final PlanCallBack planCallBack) {

    }

    @Override
    public void getOfflinePathListByPage(String token, String userid, String planIds, int pageindex, int pagesize, PlanCallBack planCallBack) {

    }

    @Override
    public void updatePathOver(final String token, final List<OfflinePathBean> pathBeanList, final PlanCallBack planCallBack) {

    }

    @Override
    public void updatePointOver(final String token, final List<OfflinePathBean> pathBeanList, final PlanCallBack planCallBack) {

    }

    /**
     *  更新当天巡检线的到位点第一次离开范围的时间
     */
    public void updatePathOffTime(final String token, final List<OfflinePathBean> pathBeanList, final PlanCallBack planCallBack){

    }

    @Override
    public void applyRecalculatePlanPercent(final String token, final String childPlanId, final String date, final PlanCallBack planCallBack) {

    }

    @Override
    public void getRecalculatePlanPoints(final String token, String childPlanId, final PlanCallBack planCallBack) {

    }

    @Override
    public void updateRecalculatePlanState(final String token, String childPlanId, final PlanCallBack planCallBack) {

    }
}
