package epson.print.copy.Component.ecopycomponent;

import android.content.Context;
import com.epson.mobilephone.common.wifidirect.ActivityControlWiFi;
import epson.common.Utils;
import epson.print.copy.Component.ecopycomponent.ECopyOptionItem;
import epson.print.copy.Component.ecopycomponent.ECopyPreview;
import epson.print.copy.Component.ecopycomponent.RemoteCopyTask;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;

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() {
        this.properties.put(Property.RequestConnectionTimeout, Integer.valueOf(ActivityControlWiFi.SCANNING_TIMEOUT));
        this.systemSettings = new ICopySystemSettings() {
            public String getPrinterIPAddress() {
                return "192.168.10.1";
            }

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

    /* renamed from: epson.print.copy.Component.ecopycomponent.ECopyComponent$3 */
    static /* synthetic */ class C21683 {

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

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

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

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

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

        ECopyComponentHolder() {
        }
    }

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

    public void getRemoteOperationUUID(Context context) {
        this.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 this.string;
            }
        }
    }

    public interface ICopyDeviceStatusListener {

        public enum Connection {
            Succeed,
            Failed
        }

        public enum DeviceState {
            Idle,
            Processing,
            Stopped
        }

        void onDeviceStatus(Connection connection, DeviceState deviceState, DeviceState deviceState2, ArrayList<PrinterStateReason> arrayList, ArrayList<ScannerStateReason> arrayList2, ArrayList<String> arrayList3);

        public enum PrinterStateReason {
            None,
            MarkerSupplyEmptyError,
            MarkerWasteFullError,
            MediaJamError,
            MediaEmptyError,
            InputTrayMissingError,
            CoverOpenError,
            OutputAreaFullError,
            OtherError,
            MarkerSupplyLowWarning,
            CoverOpen;
            
            String string;

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

        public enum ScannerStateReason {
            None,
            MediaEmptyError,
            MediaJamError,
            MediaSizeMissmatchError,
            OtherError;
            
            public String string;

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

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

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

    public ECopyPreview getComposedCopyPreview(Context context, int i, int i2, ECopyPreview.ECopyPreviewInvalidateListener eCopyPreviewInvalidateListener) {
        ECopyPreview createPreview = ECopyPreview.createPreview(context, i, i2, eCopyPreviewInvalidateListener);
        createPreview.compose(new ECopyOptionContext(this.optionContext), new ECopyPreview.ICopyPreviewCommitEditedOptionContext() {
            public void commit(ECopyOptionContext eCopyOptionContext) {
                eCopyOptionContext.getCopyOptionItemOf(ECopyOptionItem.ECopyOptionItemKey.XScale).selectChoice(RemoteCopySetOptionTask.getScaleChoice(eCopyOptionContext.copyType, eCopyOptionContext.getCopyOptionItemOf(ECopyOptionItem.ECopyOptionItemKey.CopyMagnification).getSelectedValue()));
                ECopyComponent.this.optionContext = eCopyOptionContext;
            }
        });
        return createPreview;
    }

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

    public void createCopyOptionContext(ECopyType eCopyType, ICopyOptionContextListener iCopyOptionContextListener) {
        ITask iTask;
        if (eCopyType == ECopyType.Photo) {
            iTask = new RemoteCopyPhotoGetOptionTask(eCopyType, iCopyOptionContextListener);
        } else {
            iTask = new RemoteCopyGetOptionTask(eCopyType, iCopyOptionContextListener);
        }
        execute(iTask);
    }

    public void setCopyOptionItem(ECopyOptionItem eCopyOptionItem) {
        ITask iTask;
        if (this.optionContext.getCopyType() == ECopyType.Photo) {
            iTask = new RemoteCopyPhotoSetOptionTask(eCopyOptionItem, this.optionChangedListener);
        } else {
            iTask = new RemoteCopySetOptionTask(eCopyOptionItem, this.optionChangedListener);
        }
        execute(iTask);
    }

    public ICopyCancelRequest startPreview(ECopyPreview eCopyPreview, ICopyStatusListener iCopyStatusListener) {
        return execute(new PreviewScanTask(eCopyPreview, iCopyStatusListener));
    }

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

    public ICopyCancelRequest startCopyPhoto(String str, ICopyStatusListener iCopyStatusListener) {
        return execute(new RemoteCopyPhotoTask(str, iCopyStatusListener));
    }

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

    public void getDeviceStatus(ICopyDeviceStatusListener iCopyDeviceStatusListener) {
        execute(new RemoteDeviceTask(iCopyDeviceStatusListener));
    }

    public int getCopyValue(ECopyType eCopyType, ECopyOptionItem.ECopyOptionItemChoice eCopyOptionItemChoice) {
        return RemoteCopySetOptionTask.getcopyMagnification(eCopyType, eCopyOptionItemChoice);
    }

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