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

import android.content.Context;

import com.tofly.ghrq_route.module.OfflineWork.OfflineWorkTool;
import com.tofly.ghrq_route.module.deviceInfo.domain.DeviceInfoBean;
import com.tofly.ghrq_route.module.sign.domain.SignHistoryDataBean;
import com.tofly.ghrq_route.module.sign.service.ISignService;
import com.tofly.ghrq_route.module.sign.service.SignServiceImpl;
import com.tofly.ghrq_route.module.sign.service.SignServiceImplOffline;

import java.util.List;

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

public class SignController {
    /**
     * 是否在綫
     */
    boolean mbOnline;
    /**
     * 上下文
     */
    Context mContext;
    /**
     * 签到接口实现对象
     */
    ISignService signService;

    public SignController(Context context){
        mbOnline = true;
        mContext = context;
        signService = new SignServiceImpl(context);
    }

    public SignController(boolean online, Context context){
        mbOnline = online;
        mContext = context;
        signService = new SignServiceImpl(context);
    }

    private void setSignService(){
        boolean isOffline = OfflineWorkTool.isOffline();
        if (isOffline){
            signService = new SignServiceImplOffline(mContext);
        }else {
            signService = new SignServiceImpl(mContext);
        }
    }

    /**
     *  获取当天最新签到状态
     */
    public void getSignStatusToday(Context context, String userid, final SignCallBack signCallBack){
        setSignService();
        signService.getSignStatusToday(context, userid, signCallBack);
    }

    /**
     *  获取当天签到列表
     */
    public void getSignListToday(Context context, String userid, int pageindex, int pagesize, final SignCallBack signCallBack){
        setSignService();
        signService.getSignListToday(context, userid, pageindex, pagesize, signCallBack);
    }

    /**
     * 当天签到
     * @param context
     * @param signHistory 签到记录
     * @param signCallBack
     */
    public void signToday(Context context, String userid, SignHistoryDataBean signHistory, DeviceInfoBean deviceInfo, List<String> localPlanIds, final SignCallBack signCallBack){
        signService = new SignServiceImpl(mContext);
        signService.signToday(context, userid, signHistory, deviceInfo, localPlanIds, signCallBack);
    }

    /**
     * 获取指定月份的考勤记录
     * @param context
     * @param date 指定年和月，格式 yyyy/MM
     * @param signCallBack
     */
    public void getDailyPlanAttened(Context context, String userid, String date, final SignCallBack signCallBack){
        setSignService();
        signService.getDailyPlanAttened(context, userid, date, signCallBack);
    }
}
