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

import android.content.Context;

import com.tofly.ghrq_route.base.URLResponseCode;
import com.tofly.ghrq_route.module.buildManage.BuildTool;
import com.tofly.ghrq_route.module.trouble.TroubleTool;
import com.tofly.ghrq_route.module.trouble.domain.TroubleAudioBean;
import com.tofly.ghrq_route.module.trouble.domain.TroublePictureBean;
import com.tofly.ghrq_route.module.uploadFile.controller.UploadFileCallBack;
import com.tofly.ghrq_route.module.uploadFile.domain.UploadFileBean;

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

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

public class UploadFileServiceImplOffline implements IUploadFileService {
    private Context mContext;

    public UploadFileServiceImplOffline(Context context){
        mContext = context;
    }

    @Override
    public void getUploadFileList(final String token, final String tableId, String table_name, final int pageindex, final int pagesize, final UploadFileCallBack uploadFileCallBack) {
        List<UploadFileBean> uploadFileBeans = new ArrayList<>();
        switch (table_name){
            case UploadFileBean.FILE_TABLE_TROUBLE:{
                TroubleTool troubleTool = TroubleTool.getInstance();
                List<TroublePictureBean> pictures = troubleTool.getSavedTroublePictures(tableId);
                for (TroublePictureBean pictureBean : pictures){
                    UploadFileBean picture = pictureBean.getUploadFileBean();
                    uploadFileBeans.add(picture);
                }
                List<TroubleAudioBean> audios = troubleTool.getSavedTroubleAudios(tableId);
                for (TroubleAudioBean audioBean : audios){
                    UploadFileBean audio = audioBean.getUploadFileBean();
                    uploadFileBeans.add(audio);
                }
            }
            break;
            case UploadFileBean.FILE_TABLE_BUILD_MANAGE:{
                BuildTool buildTool = BuildTool.getInstance();
                List<TroublePictureBean> pictures = buildTool.getLocalBuildPhotos(tableId, TroublePictureBean.PHOTO_UPLOADED);
                for (TroublePictureBean pictureBean : pictures){
                    UploadFileBean picture = pictureBean.getUploadFileBean();
                    uploadFileBeans.add(picture);
                }
                List<TroubleAudioBean> audios = buildTool.getLocalBuildAudios(tableId, TroublePictureBean.PHOTO_UPLOADED);
                for (TroubleAudioBean audioBean : audios){
                    UploadFileBean audio = audioBean.getUploadFileBean();
                    uploadFileBeans.add(audio);
                }
            }
            break;
            case UploadFileBean.FILE_TABLE_BUILD_REPORT:{

            }
            break;
            case UploadFileBean.FILE_TABLE_PLAN_REPAIR:{

            }
            break;
        }
        uploadFileCallBack.onGetUploadFileList(true, URLResponseCode.ErrorCode.SUCCESS_OFFLINE, "", uploadFileBeans);
    }

    @Override
    public void addUploadFile(final String token, final String tableId, final String filepath, final String filenote, final int audiolenth, final String createTime, final UploadFileCallBack uploadFileCallBack) {
        int err_code = URLResponseCode.ErrorCode.LOGIN_OFFLINE;
        uploadFileCallBack.onRemoveUploadFile(false, err_code, URLResponseCode.ErrorCode.getErrorMessage(err_code));
    }

    @Override
    public void removeUploadFile(final String token, String fileid, final UploadFileCallBack uploadFileCallBack) {
        int err_code = URLResponseCode.ErrorCode.LOGIN_OFFLINE;
        uploadFileCallBack.onRemoveUploadFile(false, err_code, URLResponseCode.ErrorCode.getErrorMessage(err_code));
    }
}
