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

import android.content.Context;

import com.tofly.ghrq_route.base.BaseApp;
import com.tofly.ghrq_route.base.URLResponseCode;
import com.tofly.ghrq_route.module.job.JobDaoHelper;
import com.tofly.ghrq_route.module.job.controller.JobCallBack;
import com.tofly.ghrq_route.module.job.domain.JobBean;
import com.tofly.ghrq_route.module.trouble.domain.TroublePictureBean;
import com.tofly.ghrq_route.module.user.domain.UserBean;

import java.util.List;

public class JobServiceImplOffline implements IJobService{

    private JobDaoHelper jobDaoHelper;

    public JobServiceImplOffline() {
        jobDaoHelper = JobDaoHelper.getInstance();
    }
    @Override
    public void getJobList(Context context, int job_state, int pageindex, int pagesize, JobCallBack jobCallBack) {
        int total = 0;
        List<JobBean> jobBeans;
        UserBean userBean = BaseApp.getInstance().getLoginUser();
        if (job_state == 0){
            jobBeans = jobDaoHelper.getJobList(userBean.getUserid());
        }else {
            int state = JobBean.JOB_TASK_STATUS.JOB_TASK_UNHANDLED.getStatus();
            switch (job_state){
                case 1:
                    state = JobBean.JOB_TASK_STATUS.JOB_TASK_UNHANDLED.getStatus();
                    break;
                case 2:
                    state = JobBean.JOB_TASK_STATUS.JOB_TASK_UNCOMMIT.getStatus();
                    break;
                case 3:
                    state = JobBean.JOB_TASK_STATUS.JOB_TASK_COMMITED.getStatus();
                    break;
            }
            jobBeans = jobDaoHelper.getJobList(userBean.getUserid(), state);
        }
        if (jobBeans != null) {
            total = jobBeans.size();
        }
        jobCallBack.onGetJobList(true, URLResponseCode.ErrorCode.SUCCESS_OFFLINE, "", jobBeans, total);
    }

    @Override
    public void uploadJobData(Context context, JobBean jobBean, List<TroublePictureBean> photos, JobCallBack jobCallBack) {

    }

    @Override
    public void getJobData(Context context, String job_id, JobCallBack jobCallBack) {
        JobBean jobBean = jobDaoHelper.getJobBean(job_id);
        jobCallBack.onGetJobData(true, URLResponseCode.ErrorCode.SUCCESS_OFFLINE, "", jobBean);
    }

    @Override
    public void getUnHandledJobCount(Context context, JobCallBack jobCallBack) {

    }
}
