package epson.print.copy.Component.ecopycomponent;

import android.os.AsyncTask;

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

import epson.print.copy.Component.eremoteoperation.ERemoteCopy;
import epson.print.copy.Component.eremoteoperation.ERemoteOperation;

class RemoteCopySetOptionTask extends AsyncTask<Void, Void, Result> implements ECopyComponent.ITask {
    public static int XScale_2L_to_A4_Value = 165;
    public static int XScale_2L_to_A4_ValueEx = 173;
    public static int XScale_2L_to_KG_Value = 77;
    public static int XScale_2L_to_Letter_Value = 157;
    public static int XScale_2L_to_Postcard_Value = 76;
    public static int XScale_2L_to_Postcard_ValueEx = 89;
    public static int XScale_8x10_to_2L_Value = 61;
    public static int XScale_A4_to_2L_Value = 59;
    public static int XScale_A4_to_A3_Value = 141;
    public static int XScale_A4_to_A5_Value = 69;
    public static int XScale_A4_to_B5_Value = 85;
    public static int XScale_A4_to_KG_Value = 47;
    public static int XScale_A4_to_Postcard_Value = 46;
    public static int XScale_A4_to_Postcard_ValueEx = 53;
    public static int XScale_A5_to_A4_Value = 141;
    public static int XScale_Autofit_Value = ECopyOptionItem.CopyMagnificationAutofitValue;
    public static int XScale_B5_to_A4_Value = 114;
    public static int XScale_B5_to_A4_ValueEx = 120;
    public static int XScale_Custom_Value = 0;
    public static int XScale_FullSize_Value = 100;
    public static int XScale_KG_to_2L_Value = 115;
    public static int XScale_KG_to_8x10_Value = 166;
    public static int XScale_KG_to_A4_Value = 195;
    public static int XScale_KG_to_Letter_Value = 183;
    public static int XScale_L_to_2L_Value = 139;
    public static int XScale_L_to_2L_ValueEx = 151;
    public static int XScale_L_to_A4_Value = 235;
    public static int XScale_L_to_A4_ValueEx = 246;
    public static int XScale_L_to_Postcard_Value = 110;
    public static int XScale_L_to_Postcard_ValueEx = 125;
    public static int XScale_Legal_to_Letter_Value = 78;
    public static int XScale_Letter_to_11x17_Value = 129;
    public static int XScale_Letter_to_2L_Value = 57;
    public static int XScale_Letter_to_KG_Value = 45;
    public static int XScale_Postcard_to_A4_Value = 201;
    public static int XScale_Postcard_to_A4_ValueEx = 219;
    ArrayList<ERemoteOperation.ERemoteParam> changableParams;
    String clientID;
    HashMap<Integer, ECopyOptionItem.ECopyOptionItemChoice> copyScaleMap;
    ERemoteCopy operation = new ERemoteCopy();
    ECopyComponent.ICopyOptionListener optionChangedListener;
    ECopyOptionContext optionContext;
    ECopyOptionItem replacedItem;
    ECopyOptionItem selectedItem;
    ECopyComponent.ICopySystemSettings systemSettings;
    HashMap<ECopyOptionItem.ECopyOptionItemChoice, Integer> xscaleMap;

    static HashMap<ECopyOptionItem.ECopyOptionItemChoice, Integer> getXScaleMap(ECopyComponent.ECopyType eCopyType) {
        HashMap<ECopyOptionItem.ECopyOptionItemChoice, Integer> hashMap = new HashMap<>();
        if (eCopyType == ECopyComponent.ECopyType.Borderless) {
            hashMap.put(ECopyOptionItem.ECopyOptionItemChoice.XScale_FullSize, new Integer(XScale_FullSize_Value));
            hashMap.put(ECopyOptionItem.ECopyOptionItemChoice.XScale_A4_to_Postcard, new Integer(XScale_A4_to_Postcard_ValueEx));
            hashMap.put(ECopyOptionItem.ECopyOptionItemChoice.XScale_2L_to_Postcard, new Integer(XScale_2L_to_Postcard_ValueEx));
            hashMap.put(ECopyOptionItem.ECopyOptionItemChoice.XScale_L_to_Postcard, new Integer(XScale_L_to_Postcard_ValueEx));
            hashMap.put(ECopyOptionItem.ECopyOptionItemChoice.XScale_L_to_2L, new Integer(XScale_L_to_2L_ValueEx));
            hashMap.put(ECopyOptionItem.ECopyOptionItemChoice.XScale_2L_to_A4, new Integer(XScale_2L_to_A4_ValueEx));
            hashMap.put(ECopyOptionItem.ECopyOptionItemChoice.XScale_Postcard_to_A4, new Integer(XScale_Postcard_to_A4_ValueEx));
            hashMap.put(ECopyOptionItem.ECopyOptionItemChoice.XScale_L_to_A4, new Integer(XScale_L_to_A4_ValueEx));
            hashMap.put(ECopyOptionItem.ECopyOptionItemChoice.XScale_B5_to_A4, new Integer(XScale_B5_to_A4_ValueEx));
            hashMap.put(ECopyOptionItem.ECopyOptionItemChoice.XScale_Custom, new Integer(XScale_Custom_Value));
            hashMap.put(ECopyOptionItem.ECopyOptionItemChoice.XScale_Autofit, new Integer(XScale_Autofit_Value));
        } else if (eCopyType == ECopyComponent.ECopyType.Mirror) {
            hashMap.put(ECopyOptionItem.ECopyOptionItemChoice.XScale_FullSize, new Integer(XScale_FullSize_Value));
            hashMap.put(ECopyOptionItem.ECopyOptionItemChoice.XScale_Custom, new Integer(XScale_Custom_Value));
            hashMap.put(ECopyOptionItem.ECopyOptionItemChoice.XScale_Autofit, new Integer(XScale_Autofit_Value));
        } else if (eCopyType == ECopyComponent.ECopyType.Standard) {
            hashMap.put(ECopyOptionItem.ECopyOptionItemChoice.XScale_FullSize, new Integer(XScale_FullSize_Value));
            hashMap.put(ECopyOptionItem.ECopyOptionItemChoice.XScale_Custom, new Integer(XScale_Custom_Value));
            hashMap.put(ECopyOptionItem.ECopyOptionItemChoice.XScale_Autofit, new Integer(XScale_Autofit_Value));
            hashMap.put(ECopyOptionItem.ECopyOptionItemChoice.XScale_Letter_to_KG, new Integer(XScale_Letter_to_KG_Value));
            hashMap.put(ECopyOptionItem.ECopyOptionItemChoice.XScale_KG_to_Letter, new Integer(XScale_KG_to_Letter_Value));
            hashMap.put(ECopyOptionItem.ECopyOptionItemChoice.XScale_Letter_to_2L, new Integer(XScale_Letter_to_2L_Value));
            hashMap.put(ECopyOptionItem.ECopyOptionItemChoice.XScale_2L_to_Letter, new Integer(XScale_2L_to_Letter_Value));
            hashMap.put(ECopyOptionItem.ECopyOptionItemChoice.XScale_KG_to_A4, new Integer(XScale_KG_to_A4_Value));
            hashMap.put(ECopyOptionItem.ECopyOptionItemChoice.XScale_A4_to_KG, new Integer(XScale_A4_to_KG_Value));
            hashMap.put(ECopyOptionItem.ECopyOptionItemChoice.XScale_2L_to_A4, new Integer(XScale_2L_to_A4_Value));
            hashMap.put(ECopyOptionItem.ECopyOptionItemChoice.XScale_A4_to_2L, new Integer(XScale_A4_to_2L_Value));
            hashMap.put(ECopyOptionItem.ECopyOptionItemChoice.XScale_KG_to_8x10, new Integer(XScale_KG_to_8x10_Value));
            hashMap.put(ECopyOptionItem.ECopyOptionItemChoice.XScale_8x10_to_2L, new Integer(XScale_8x10_to_2L_Value));
            hashMap.put(ECopyOptionItem.ECopyOptionItemChoice.XScale_Legal_to_Letter, new Integer(XScale_Legal_to_Letter_Value));
            hashMap.put(ECopyOptionItem.ECopyOptionItemChoice.XScale_A4_to_Postcard, new Integer(XScale_A4_to_Postcard_Value));
            hashMap.put(ECopyOptionItem.ECopyOptionItemChoice.XScale_2L_to_Postcard, new Integer(XScale_2L_to_Postcard_Value));
            hashMap.put(ECopyOptionItem.ECopyOptionItemChoice.XScale_L_to_Postcard, new Integer(XScale_L_to_Postcard_Value));
            hashMap.put(ECopyOptionItem.ECopyOptionItemChoice.XScale_L_to_2L, new Integer(XScale_L_to_2L_Value));
            hashMap.put(ECopyOptionItem.ECopyOptionItemChoice.XScale_Postcard_to_A4, new Integer(XScale_Postcard_to_A4_Value));
            hashMap.put(ECopyOptionItem.ECopyOptionItemChoice.XScale_L_to_A4, new Integer(XScale_L_to_A4_Value));
            hashMap.put(ECopyOptionItem.ECopyOptionItemChoice.XScale_A4_to_B5, new Integer(XScale_A4_to_B5_Value));
            hashMap.put(ECopyOptionItem.ECopyOptionItemChoice.XScale_B5_to_A4, new Integer(XScale_B5_to_A4_Value));
            hashMap.put(ECopyOptionItem.ECopyOptionItemChoice.XScale_2L_to_KG, new Integer(XScale_2L_to_KG_Value));
            hashMap.put(ECopyOptionItem.ECopyOptionItemChoice.XScale_KG_to_2L, new Integer(XScale_KG_to_2L_Value));
            hashMap.put(ECopyOptionItem.ECopyOptionItemChoice.XScale_A5_to_A4, new Integer(XScale_A5_to_A4_Value));
            hashMap.put(ECopyOptionItem.ECopyOptionItemChoice.XScale_A4_to_A5, new Integer(XScale_A4_to_A5_Value));
            hashMap.put(ECopyOptionItem.ECopyOptionItemChoice.XScale_A4_to_A3, new Integer(XScale_A4_to_A3_Value));
            hashMap.put(ECopyOptionItem.ECopyOptionItemChoice.XScale_Letter_to_11x17, new Integer(XScale_Letter_to_11x17_Value));
        } else {
            hashMap.put(ECopyOptionItem.ECopyOptionItemChoice.XScale_FullSize, new Integer(XScale_FullSize_Value));
            hashMap.put(ECopyOptionItem.ECopyOptionItemChoice.XScale_A4_to_Postcard, new Integer(XScale_A4_to_Postcard_Value));
            hashMap.put(ECopyOptionItem.ECopyOptionItemChoice.XScale_2L_to_Postcard, new Integer(XScale_2L_to_Postcard_Value));
            hashMap.put(ECopyOptionItem.ECopyOptionItemChoice.XScale_L_to_Postcard, new Integer(XScale_L_to_Postcard_Value));
            hashMap.put(ECopyOptionItem.ECopyOptionItemChoice.XScale_L_to_2L, new Integer(XScale_L_to_2L_Value));
            hashMap.put(ECopyOptionItem.ECopyOptionItemChoice.XScale_2L_to_A4, new Integer(XScale_2L_to_A4_Value));
            hashMap.put(ECopyOptionItem.ECopyOptionItemChoice.XScale_Postcard_to_A4, new Integer(XScale_Postcard_to_A4_Value));
            hashMap.put(ECopyOptionItem.ECopyOptionItemChoice.XScale_L_to_A4, new Integer(XScale_L_to_A4_Value));
            hashMap.put(ECopyOptionItem.ECopyOptionItemChoice.XScale_A4_to_B5, new Integer(XScale_A4_to_B5_Value));
            hashMap.put(ECopyOptionItem.ECopyOptionItemChoice.XScale_B5_to_A4, new Integer(XScale_B5_to_A4_Value));
            hashMap.put(ECopyOptionItem.ECopyOptionItemChoice.XScale_Custom, new Integer(XScale_Custom_Value));
            hashMap.put(ECopyOptionItem.ECopyOptionItemChoice.XScale_Autofit, new Integer(XScale_Autofit_Value));
        }
        return hashMap;
    }

    static HashMap<Integer, ECopyOptionItem.ECopyOptionItemChoice> getCopyMagnificationMap(HashMap<ECopyOptionItem.ECopyOptionItemChoice, Integer> hashMap) {
        HashMap<Integer, ECopyOptionItem.ECopyOptionItemChoice> hashMap2 = new HashMap<>();
        for (ECopyOptionItem.ECopyOptionItemChoice next : hashMap.keySet()) {
            hashMap2.put(Integer.valueOf(hashMap.get(next).intValue()), next);
        }
        return hashMap2;
    }

    public static ECopyOptionItem.ECopyOptionItemChoice getScaleChoice(ECopyComponent.ECopyType eCopyType, int i) {
        ECopyOptionItem.ECopyOptionItemChoice eCopyOptionItemChoice = getCopyMagnificationMap(getXScaleMap(eCopyType)).get(Integer.valueOf(i));
        return eCopyOptionItemChoice != null ? eCopyOptionItemChoice : ECopyOptionItem.ECopyOptionItemChoice.XScale_Custom;
    }

    public static int getcopyMagnification(ECopyComponent.ECopyType eCopyType, ECopyOptionItem.ECopyOptionItemChoice eCopyOptionItemChoice) {
        int intValue = getXScaleMap(eCopyType).get(eCopyOptionItemChoice).intValue();
        if (intValue != 0) {
            return intValue;
        }
        return 0;
    }

    class Result {
        ArrayList<ECopyOptionItem> changedItems;
        ECopyComponent.ICopyOptionListener.CopyOptionChangedError error;
        ECopyOptionItem selectedItem;

        Result() {
        }
    }

    public RemoteCopySetOptionTask(ECopyOptionItem eCopyOptionItem, ECopyComponent.ICopyOptionListener iCopyOptionListener) {
        selectedItem = eCopyOptionItem;
        optionChangedListener = iCopyOptionListener;
    }

    public static int scaleValue(ECopyOptionItem.ECopyOptionItemChoice eCopyOptionItemChoice) {
        return getXScaleMap(ECopyComponent.ECopyType.Standard).get(eCopyOptionItemChoice).intValue();
    }

    public ECopyComponent.ICopyCancelRequest start() {
        super.execute(new Void[0]);
        return null;
    }

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

    public void setRequestConnectionTimeout(int i) {
        operation.setRequestConnectionTimeout(i);
    }

    public void setClientID(String str) {
        clientID = str;
    }

    public void setOptionContext(ECopyOptionContext eCopyOptionContext) {
        optionContext = eCopyOptionContext;
        replacedItem = optionContext.replace(new ECopyOptionItem(this.selectedItem));
        changableParams = new ArrayList<>();
        changableParams.add(ERemoteOperation.ERemoteParam.print_media_size);
        changableParams.add(ERemoteOperation.ERemoteParam.print_media_type);
        changableParams.add(ERemoteOperation.ERemoteParam.scan_content_type);
        changableParams.add(ERemoteOperation.ERemoteParam.print_media_source);
        changableParams.add(ERemoteOperation.ERemoteParam.print_quality);
        xscaleMap = getXScaleMap(eCopyOptionContext.copyType);
        copyScaleMap = getCopyMagnificationMap(this.xscaleMap);
    }

    public Result getResultLocalOptions() {
        Result result = new Result();
        result.selectedItem = selectedItem;
        result.changedItems = new ArrayList<>();
        ECopyOptionItem.ECopyOptionItemKey key = selectedItem.getKey();
        if (key == ECopyOptionItem.ECopyOptionItemKey.CopyMagnification) {
            result.changedItems.add(this.optionContext.getCopyOptionItemOf(ECopyOptionItem.ECopyOptionItemKey.XScale));
        } else if (key == ECopyOptionItem.ECopyOptionItemKey.XScale) {
            ECopyOptionItem copyOptionItemOf = optionContext.getCopyOptionItemOf(ECopyOptionItem.ECopyOptionItemKey.CopyMagnification);
            int intValue = xscaleMap.get(this.selectedItem.getSelectedChoice()).intValue();
            if (intValue != XScale_Custom_Value) {
                copyOptionItemOf.selectValue(intValue);
            }
            if (intValue != ECopyOptionItem.CopyMagnificationAutofitValue) {
                copyOptionItemOf.enabled = true;
            } else {
                copyOptionItemOf.enabled = false;
            }
            result.changedItems.add(copyOptionItemOf);
        } else {
            result.changedItems = null;
        }
        return result;
    }

    protected Result doInBackground(Void... voidArr) {
        operation.setHostIP(this.systemSettings.getPrinterIPAddress());
        if (this.selectedItem.isLocalOption) {
            return getResultLocalOptions();
        }
        ERemoteCopy.ERemoteCopyOptionsResult options = operation.getOptions(new ERemoteCopy.IRemoteCopyOptionsParameter() {
            public boolean default_as_fixed() {
                return true;
            }

            public String client_id() {
                return RemoteCopySetOptionTask.this.clientID;
            }

            public ERemoteOperation.ERemoteParam layout() {
                return ECopyOptionItem.layoutOf(RemoteCopySetOptionTask.this.optionContext.getCopyType());
            }

            public ERemoteOperation.ERemoteParam scan_sides() {
                return RemoteCopySetOptionTask.this.optionContext.getCopyOptionsResult().parameter_default(ERemoteOperation.ERemoteParam.scan_sides);
            }

            public ERemoteOperation.ERemoteParam print_sides() {
                return RemoteCopySetOptionTask.this.optionContext.getCopyOptionsResult().parameter_default(ERemoteOperation.ERemoteParam.print_sides);
            }

            public ERemoteOperation.ERemoteParam scan_media_size() {
                return RemoteCopySetOptionTask.this.optionContext.getCopyOptionsResult().parameter_default(ERemoteOperation.ERemoteParam.scan_media_size);
            }

            public ERemoteOperation.ERemoteParam scan_content_type() {
                return RemoteCopySetOptionTask.this.optionContext.getCopyOptionItemOf(ECopyOptionItem.ECopyOptionItemKey.ScanContentType).getSelectedChoice().param;
            }

            public ERemoteOperation.ERemoteParam print_media_type() {
                return RemoteCopySetOptionTask.this.optionContext.getCopyOptionItemOf(ECopyOptionItem.ECopyOptionItemKey.PrintMediaType).getSelectedChoice().param;
            }

            public ERemoteOperation.ERemoteParam print_media_size() {
                return RemoteCopySetOptionTask.this.optionContext.getCopyOptionItemOf(ECopyOptionItem.ECopyOptionItemKey.PrintMediaSize).getSelectedChoice().param;
            }

            public ERemoteOperation.ERemoteParam print_media_source() {
                return RemoteCopySetOptionTask.this.optionContext.getCopyOptionItemOf(ECopyOptionItem.ECopyOptionItemKey.PrintMediaSource).getSelectedChoice().param;
            }

            public ERemoteOperation.ERemoteParam print_quality() {
                return RemoteCopySetOptionTask.this.optionContext.getCopyOptionItemOf(ECopyOptionItem.ECopyOptionItemKey.PrintQuality).getSelectedChoice().param;
            }

            public ERemoteOperation.ERemoteParam print_sheet_collate() {
                return RemoteCopySetOptionTask.this.optionContext.getCopyOptionsResult().parameter_default(ERemoteOperation.ERemoteParam.print_sheet_collate);
            }

            public ArrayList<ERemoteOperation.ERemoteParam> fixed_parameters() {
                return new ArrayList<>();
            }

            public ArrayList<ERemoteOperation.ERemoteParam> preferred_parameters() {
                ArrayList<ERemoteOperation.ERemoteParam> arrayList = new ArrayList<>();
                arrayList.add(ERemoteOperation.ERemoteParam.print_sheet_collate);
                arrayList.add(ERemoteOperation.ERemoteParam.scan_sides);
                arrayList.add(ERemoteOperation.ERemoteParam.layout);
                arrayList.add(ERemoteOperation.ERemoteParam.print_sides);
                arrayList.add(ERemoteOperation.ERemoteParam.scan_media_size);
                arrayList.add(ERemoteOperation.ERemoteParam.print_media_size);
                arrayList.add(ERemoteOperation.ERemoteParam.print_media_type);
                arrayList.add(ERemoteOperation.ERemoteParam.scan_content_type);
                arrayList.add(ERemoteOperation.ERemoteParam.print_quality);
                arrayList.add(ERemoteOperation.ERemoteParam.print_media_source);
                return arrayList;
            }

            public ArrayList<ERemoteOperation.ERemoteParam> priority_order() {
                ArrayList<ERemoteOperation.ERemoteParam> arrayList = new ArrayList<>();
                arrayList.add(ERemoteOperation.ERemoteParam.print_sheet_collate);
                arrayList.add(ERemoteOperation.ERemoteParam.scan_sides);
                arrayList.add(ERemoteOperation.ERemoteParam.layout);
                arrayList.add(ERemoteOperation.ERemoteParam.print_sides);
                arrayList.add(ERemoteOperation.ERemoteParam.scan_media_size);
                arrayList.add(ERemoteOperation.ERemoteParam.print_media_size);
                arrayList.add(ERemoteOperation.ERemoteParam.print_media_type);
                arrayList.add(ERemoteOperation.ERemoteParam.scan_content_type);
                arrayList.add(ERemoteOperation.ERemoteParam.print_quality);
                arrayList.add(ERemoteOperation.ERemoteParam.print_media_source);
                return arrayList;
            }
        });
        Result result = new Result();
        result.selectedItem = selectedItem;
        if (options.success()) {
            optionContext.setCopyOptionsResult(options);
            result.changedItems = new ArrayList<>();
            Iterator<ERemoteOperation.ERemoteParam> it = changableParams.iterator();
            while (it.hasNext()) {
                ECopyOptionItem createOptionItem = ECopyOptionItem.createOptionItem(it.next(), options);
                if (this.optionContext.isChanged(createOptionItem)) {
                    result.changedItems.add(createOptionItem);
                    optionContext.replace(createOptionItem);
                }
            }
            if (result.changedItems.size() == 0) {
                result.changedItems = null;
            }
        } else {
            if (options.isNull(ERemoteOperation.ERemoteParam.success)) {
                result.error = ECopyComponent.ICopyOptionListener.CopyOptionChangedError.ErrorCommunication;
            } else {
                result.error = ECopyComponent.ICopyOptionListener.CopyOptionChangedError.Error;
            }
            result.selectedItem = new ECopyOptionItem(this.replacedItem);
            optionContext.replace(this.replacedItem);
        }
        return result;
    }

    protected void onPostExecute(Result result) {
        optionChangedListener.onCopyOptionChanged(result.selectedItem, result.changedItems, result.error);
    }
}
