package epson.print.rpcopy.Component.ecopycomponent;

import android.content.Context;

import com.epson.mobilephone.common.wifidirect.ActivityControlWiFi;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;

import epson.common.Utils;

public final class ECopyComponent {
    String clientID;
    ICopyOptionListener optionChangedListener;
    ECopyOptionContext optionContext = new ECopyOptionContext();
    HashMap<Property, Object> properties = new HashMap<>();
    ICopySystemSettings systemSettings;

    public enum ECopyType {
        Standard,
        Borderless,
        A4_2up,
        B5_2up,
        A4_2up_Book,
        B5_2up_Book,
        Mirror,
        Photo
    }

    public interface ICopyCancelRequest {
        void cancel();
    }

    interface ICopyInvalidateResumeRequest extends ICopyResumeRequest {
        void invalidate();
    }

    public interface ICopyOptionContextListener {

        public enum ContextCreationError {
            ErrorCommunication,
            ErrorNotCopySupported,
            Error
        }

        void onCopyOptionContextCreated(ECopyType eCopyType, ECopyOptionContext eCopyOptionContext, ContextCreationError contextCreationError);
    }

    public interface ICopyOptionListener {

        public enum CopyOptionChangedError {
            ErrorCommunication,
            ErrorInvalidOption,
            Error
        }

        void onCopyOptionChanged(ECopyOptionItem eCopyOptionItem, ArrayList<ECopyOptionItem> arrayList, CopyOptionChangedError copyOptionChangedError);
    }

    public interface ICopyStatusListener {

        public enum CopyTaskProgress {
            Copying,
            Waiting2ndPage,
            Canceling,
            Scanning,
            Stopped,
            Processing
        }

        public enum CopyTaskResult {
            Succeed,
            Canceled,
            Busy,
            ErrorInvalidOption,
            ErrorCommunication,
            RemoveAdfPaper,
            ErrorOther
        }

        public enum CopyTaskType {
            Preview,
            Copy
        }

        void onFinished(CopyTaskType copyTaskType, CopyTaskResult copyTaskResult);

        void onProcessed(CopyTaskType copyTaskType, int i, int i2, CopyTaskProgress copyTaskProgress, ICopyResumeRequest iCopyResumeRequest);

        void onStarted(CopyTaskType copyTaskType);
    }

    public interface ICopySystemSettings {
        String getPrinterIPAddress();

        int getThickPaper();
    }

    protected interface ITask {
        void setClientID(String str);

        void setOptionContext(ECopyOptionContext eCopyOptionContext);

        void setRequestConnectionTimeout(int i);

        void setSystemSettings(ICopySystemSettings iCopySystemSettings);

        ICopyCancelRequest start();
    }

    public enum Property {
        RequestConnectionTimeout
    }

    ECopyComponent() {
        properties.put(Property.RequestConnectionTimeout, Integer.valueOf(ActivityControlWiFi.SCANNING_TIMEOUT));
        systemSettings = new ICopySystemSettings() {
            public String getPrinterIPAddress() {
                return "192.168.10.1";
            }

            public int getThickPaper() {
                return 0;
            }
        };
    }

    /* renamed from: epson.print.rpcopy.Component.ecopycomponent.ECopyComponent$2 */
    static /* synthetic */ class C22622 {

        /* renamed from: $SwitchMap$epson$print$rpcopy$Component$ecopycomponent$ECopyComponent$Property */
        static final /* synthetic */ int[] f392x2fb1f0b9 = new int[Property.values().length];

        static {
            try {
                f392x2fb1f0b9[Property.RequestConnectionTimeout.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
        }
    }

    public void setProperty(Property property, int i) {
        if (C22622.f392x2fb1f0b9[property.ordinal()] == 1) {
            properties.put(property, Integer.valueOf(i));
        }
    }

    public void setSystemSettings(ICopySystemSettings iCopySystemSettings) {
        systemSettings = iCopySystemSettings;
    }

    static class ECopyComponentHolder {
        static final ECopyComponent instance = new ECopyComponent();

        ECopyComponentHolder() {
        }
    }

    public static ECopyComponent sharedComponent() {
        return ECopyComponentHolder.instance;
    }

    public void getRemoteOperationUUID(Context context) {
        clientID = Utils.getRemoteOperationUUID(context);
    }

    public interface ICopyResumeRequest {

        public enum ResumeState {
            NextPageReady,
            NextPageNotExist,
            ClearError,
            Cancel
        }

        StopReason getStopReason();

        boolean isPossibleClearError();

        void resume(ResumeState resumeState);

        public enum StopReason {
            None,
            ChangePage,
            PrinterMarkerSupplyEmptyError,
            PrinterMarkerWasteFullError,
            PrinterMediaJamError,
            PrinterMediaEmptyError,
            ManualfeedGuide,
            PrinterInputTrayMissingError,
            PrinterCoverOpenError,
            PrinterOutputAreaFullError,
            PrinterOtherError,
            ScannerMediaEmptyError,
            ScannerMediaJamError,
            ScannerMediaSizeMissmatchError,
            ScannerOtherError;

            String string;

            public String getDebugString() {
                return string;
            }
        }
    }

    public void bindCopyOptionContext(ECopyOptionContext eCopyOptionContext, ICopyOptionListener iCopyOptionListener) {
        optionContext = new ECopyOptionContext(eCopyOptionContext);
        optionChangedListener = iCopyOptionListener;
    }

    public ECopyOptionContext getBindedCopyOptionContext() {
        if (this.optionContext.isNull()) {
            return null;
        }
        return optionContext;
    }

    public ArrayList<ECopyOptionItem> getCopyOptionItems() {
        ArrayList<ECopyOptionItem> arrayList = new ArrayList<>();
        Iterator<ECopyOptionItem> it = optionContext.optionItems.iterator();
        while (it.hasNext()) {
            arrayList.add(new ECopyOptionItem(it.next()));
        }
        return arrayList;
    }

    public static void createCopyOptionContext(ECopyComponent eCopyComponent, ECopyType eCopyType, ICopyOptionContextListener iCopyOptionContextListener) {
        eCopyComponent.execute(new RemoteCopyGetOptionTask(eCopyType, iCopyOptionContextListener));
    }

    public void setCopyOptionItem(ECopyOptionItem eCopyOptionItem) {
        execute(new RemoteCopySetOptionTask(eCopyOptionItem, optionChangedListener));
    }

    public ICopyCancelRequest startCopy(ICopyStatusListener iCopyStatusListener, Context context) {
        return execute(new RemoteCopyTask(RemoteCopyTask.CopyMode.Copy, iCopyStatusListener, context));
    }

    public ICopyCancelRequest recoverCopy(String str, ICopyStatusListener iCopyStatusListener) {
        return execute(new RemoteCopyTask(RemoteCopyTask.CopyMode.Recover, str, iCopyStatusListener, (Context) null));
    }

    protected ICopyCancelRequest execute(ITask iTask) {
        iTask.setSystemSettings(this.systemSettings);
        iTask.setRequestConnectionTimeout(((Integer) properties.get(Property.RequestConnectionTimeout)).intValue());
        iTask.setClientID(this.clientID);
        iTask.setOptionContext(this.optionContext);
        return iTask.start();
    }
}
