package com.epson.iprint.storage;

import android.app.Activity;
import android.content.Context;

import android.widget.ImageView;
import com.epson.iprint.storage.box.BoxNetClient;
import com.epson.iprint.storage.dropbox.DropboxV2Client;
import com.epson.iprint.storage.evernote.EvernoteClient;
import com.epson.iprint.storage.gdrivev3.GoogleV3UploadClient;
import com.epson.iprint.storage.onedrive.OneDriveClient;
import epson.common.Utils;
import epson.print.CommonDefine;
import epson.print.fileBrower;
import java.util.List;
import org.apache.commons.lang.CharEncoding;

public abstract class StorageServiceClient {
    public static final String EPSON_IPRINT_FOLDER = "Epson iPrint";
    public static String STORAGE_BOX = "box";
    public static final String STORAGE_DROPBOX = "dropbox";
    public static String STORAGE_EVERNOTE = "evernote";
    public static String STORAGE_GOOGLEDRIVE = "googledrive";
    public static String STORAGE_ONEDRIVE = "onedrive";

    public interface DownloadCompletion {
        void onDownloadComplete(StorageItem storageItem, String str, ProcessError processError);
    }

    public interface EnumerateCompletion {
        void onEnumerateComplete(List<StorageItem> list, ProcessError processError);
    }

    public enum ProcessError {
        NONE,
        CANCELED,
        RETRY,
        ERROR
    }

    public interface SigninCompletion {
        void onSigninCompletion();
    }

    public interface UploadCompletion {
        void onUploadComplete(String str, String str2, ProcessError processError);
    }

    public enum UploadFileType {
        PDF,
        JPEG
    }

    public abstract Downloader getDownloader(Context context, StorageItem storageItem, String str);

    public abstract Enumerator getEnumerator(Context context);

    public abstract String getStorageServiceName(Context context);

    public abstract Uploader getUploader(Context context, UploadFileType uploadFileType, String str, String str2);

    protected boolean isNeedSignin() {
        return false;
    }

    public abstract boolean isSignedIn(Context context);

    public abstract boolean isSupportedUploadType(UploadFileType uploadFileType);

    public abstract boolean revokeSignedInData(Activity activity);

    public static StorageServiceClient getClient(String str) {
        if (str.equals(STORAGE_GOOGLEDRIVE)) {
            return new GoogleV3UploadClient();
        }
        if (str.equals(STORAGE_DROPBOX)) {
            return new DropboxV2Client();
        }
        if (str.equals(STORAGE_BOX)) {
            return BoxNetClient.getInstance();
        }
        if (str.equals(STORAGE_EVERNOTE)) {
            return new EvernoteClient();
        }
        if (str.equals(STORAGE_ONEDRIVE)) {
            return new OneDriveClient();
        }
        return null;
    }

    public abstract class Uploader {
        public void cancel() {
        }

        public abstract boolean isCancelable();

        public abstract void start(UploadCompletion uploadCompletion);

        public Uploader() {
        }
    }

    public abstract class Downloader {
        public void cancel() {
        }

        public abstract boolean isCancelable();

        public abstract void start(DownloadCompletion downloadCompletion);

        public Downloader() {
        }
    }

    public abstract class Enumerator {
        public void cleanUpResources() {
        }

        public abstract void enumerate(StorageItem storageItem, EnumerateCompletion enumerateCompletion);

        public void enumerate(StorageItem storageItem, EnumerateCompletion enumerateCompletion, SigninCompletion signinCompletion) {
        }

        public abstract StorageItem getRootItem();

        public void setThumbnailInBackground(StorageItem storageItem, ImageView imageView) {
        }

        public Enumerator() {
        }
    }

    protected boolean isValidUploadName(String str) {
        try {
            byte[] bytes = str.getBytes(CharEncoding.UTF_8);
            if (bytes != null) {
                if (bytes.length <= 64) {
                    if (!fileBrower.isAvailableFileName(str)) {
                        return false;
                    }
                    return true;
                }
            }
            return false;
        } catch (Exception unused) {
            return false;
        }
    }

    protected boolean isPrintableFileTypes(StorageItem storageItem) {
        return isPrintableFilename(storageItem.name);
    }

    public static boolean isPrintableFilename(@Nullable String str) {
        if (str == null) {
            return false;
        }
        return Utils.isPhotoFile(str) || StorageItem.endsWith(str, CommonDefine.FileType_PDF) || Utils.isGConvertFile(str);
    }

    protected String getDownloadLocalPath(Context context, StorageItem storageItem) {
        return storageItem.getDownloadLocalPath(context);
    }
}
