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

import android.content.Context;

import com.tofly.ghrq_route.module.OfflineWork.OfflineWorkTool;
import com.tofly.ghrq_route.module.uploadFile.service.IUploadFileService;
import com.tofly.ghrq_route.module.uploadFile.service.UploadFileServiceImpl;
import com.tofly.ghrq_route.module.uploadFile.service.UploadFileServiceImplOffline;

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

public class UploadFileController {
    /**
     * 是否在綫
     */
    boolean mbOnline;
    /**
     * 上下文
     */
    Context mContext;
    /**
     * UploadFile接口实现对象
     */
    IUploadFileService uploadFileService;

    public UploadFileController(Context context){
        mbOnline = true;
        mContext = context;
        uploadFileService = new UploadFileServiceImpl(context);
    }

    public UploadFileController(boolean online, Context context){
        mbOnline = online;
        mContext = context;
        uploadFileService = new UploadFileServiceImpl(context);
    }

    private void setSignService(){
        boolean isOffline = OfflineWorkTool.isOffline();
        if (isOffline){
            uploadFileService = new UploadFileServiceImplOffline(mContext);
        }else {
            uploadFileService = new UploadFileServiceImpl(mContext);
        }
    }

    /**
     * 获取上传文件列表
     * @param token
     * @param tableId  上传文件的tableId
     * @param pageindex 当前页index
     * @param pagesize  每页数据大小
     * @param uploadFileCallBack
     */

    public void getUploadFileList(String token, String tableId, String table_name, int pageindex, int pagesize, final UploadFileCallBack uploadFileCallBack){
        setSignService();
        uploadFileService.getUploadFileList(token, tableId, table_name, pageindex, pagesize, uploadFileCallBack);
    }

    public void addUploadRepairPhoto(String token, String tableId, String filepath, String filenote, UploadFileCallBack uploadFileCallBack){
        setSignService();
        uploadFileService.addUploadFile(token, tableId, filepath, filenote, -1, "", uploadFileCallBack);
    }

    public void addUploadNoticePhoto(String token, String tableId, String filepath, String fileNote, String createTime, UploadFileCallBack uploadFileCallBack){
        uploadFileService = new UploadFileServiceImpl(mContext);
        uploadFileService.addUploadFile(token, tableId, filepath, fileNote, -1, createTime, uploadFileCallBack);
    }

    public void addUploadNoticeAudio(String token, String tableId, String filepath, String fileNote, int audiolength, String createTime, UploadFileCallBack uploadFileCallBack){
        uploadFileService = new UploadFileServiceImpl(mContext);
        uploadFileService.addUploadFile(token, tableId, filepath, fileNote, audiolength, createTime, uploadFileCallBack);
    }

    /**
     *  上传图片文件
     * @param token
     * @param fileid  上传文件的id
     * @param uploadFileCallBack
     */
    public void removeUploadFile(String token, String fileid, UploadFileCallBack uploadFileCallBack){
        setSignService();
        uploadFileService.removeUploadFile(token, fileid, uploadFileCallBack);
    }
}
