package epson.print.rpcopy.Component.ecopycomponent;

import android.os.AsyncTask;

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

import epson.print.rpcopy.Component.eremoteoperation.ERemoteCopy;
import epson.print.rpcopy.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;
    private ArrayList<ERemoteOperation.ERemoteParam> changableParams;
    String clientID;
    ERemoteCopy operation = new ERemoteCopy();
    ECopyComponent.ICopyOptionListener optionChangedListener;
    ECopyOptionContext optionContext;
    ECopyOptionItem replacedItem;
    ECopyOptionItem selectedItem;
    ECopyComponent.ICopySystemSettings systemSettings;

    @Deprecated
    static HashMap<ECopyOptionItem.ECopyOptionItemChoice, Integer> getXScaleMap(ECopyComponent.ECopyType eCopyType) {
        return null;
    }

    static HashMap<Integer, ECopyOptionItem.ECopyOptionItemChoice> getCopyMagnificationMap(HashMap<ECopyOptionItem.ECopyOptionItemChoice, Integer> hashMap) {
        return new HashMap<>();
    }

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

        Result() {
        }
    }

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

    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.color_effects_type);
        changableParams.add(ERemoteOperation.ERemoteParam.layout);
        changableParams.add(ERemoteOperation.ERemoteParam.print_media_size);
        changableParams.add(ERemoteOperation.ERemoteParam.print_media_type);
        changableParams.add(ERemoteOperation.ERemoteParam.print_media_source);
        changableParams.add(ERemoteOperation.ERemoteParam.print_quality);
        changableParams.add(ERemoteOperation.ERemoteParam.x_remove_background);
        changableParams.add(ERemoteOperation.ERemoteParam.x_cut_line);
        changableParams.add(ERemoteOperation.ERemoteParam.x_cut_line_style);
        changableParams.add(ERemoteOperation.ERemoteParam.x_cut_line_weight);
    }

    public Result getResultLocalOptions() {
        Result result = new Result();
        result.selectedItem = selectedItem;
        result.changedItems = new ArrayList<>();
        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 ERemoteOperation.ERemoteParam print_sides() {
                return null;
            }

            public ERemoteOperation.ERemoteParam scan_content_type() {
                return null;
            }

            public ERemoteOperation.ERemoteParam scan_media_size() {
                return null;
            }

            public ERemoteOperation.ERemoteParam scan_sides() {
                return null;
            }

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

            public ERemoteOperation.ERemoteParam layout() {
                return RemoteCopySetOptionTask.this.optionContext.getCopyOptionItemOf(ECopyOptionItem.ECopyOptionItemKey.RepeatLayout).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.color_effects_type);
                arrayList.add(ERemoteOperation.ERemoteParam.layout);
                arrayList.add(ERemoteOperation.ERemoteParam.print_media_size);
                arrayList.add(ERemoteOperation.ERemoteParam.print_media_type);
                arrayList.add(ERemoteOperation.ERemoteParam.print_media_source);
                arrayList.add(ERemoteOperation.ERemoteParam.print_quality);
                arrayList.add(ERemoteOperation.ERemoteParam.x_remove_background);
                if (C22702.f396xec9cd424[RemoteCopySetOptionTask.this.optionContext.getCopyOptionItemOf(ECopyOptionItem.ECopyOptionItemKey.XCutLine).getSelectedChoice().ordinal()] != 1) {
                    arrayList.add(ERemoteOperation.ERemoteParam.x_cut_line);
                    arrayList.add(ERemoteOperation.ERemoteParam.x_cut_line_style);
                    arrayList.add(ERemoteOperation.ERemoteParam.x_cut_line_weight);
                }
                return arrayList;
            }

            public ArrayList<ERemoteOperation.ERemoteParam> priority_order() {
                ArrayList<ERemoteOperation.ERemoteParam> arrayList = new ArrayList<>();
                arrayList.add(ERemoteOperation.ERemoteParam.color_effects_type);
                arrayList.add(ERemoteOperation.ERemoteParam.layout);
                arrayList.add(ERemoteOperation.ERemoteParam.print_media_size);
                arrayList.add(ERemoteOperation.ERemoteParam.print_media_type);
                arrayList.add(ERemoteOperation.ERemoteParam.print_media_source);
                arrayList.add(ERemoteOperation.ERemoteParam.print_quality);
                arrayList.add(ERemoteOperation.ERemoteParam.x_remove_background);
                if (C22702.f396xec9cd424[RemoteCopySetOptionTask.this.optionContext.getCopyOptionItemOf(ECopyOptionItem.ECopyOptionItemKey.XCutLine).getSelectedChoice().ordinal()] != 1) {
                    arrayList.add(ERemoteOperation.ERemoteParam.x_cut_line);
                    arrayList.add(ERemoteOperation.ERemoteParam.x_cut_line_style);
                    arrayList.add(ERemoteOperation.ERemoteParam.x_cut_line_weight);
                }
                return arrayList;
            }
        }, optionContext.getCopyOptionItemOf(ECopyOptionItem.ECopyOptionItemKey.RemoveBackground).getSelectedChoice().param, optionContext.getCopyOptionItemOf(ECopyOptionItem.ECopyOptionItemKey.ColorEffectsType).getSelectedChoice().param, optionContext.getCopyOptionItemOf(ECopyOptionItem.ECopyOptionItemKey.XCutLine).getSelectedChoice().param, optionContext.getCopyOptionItemOf(ECopyOptionItem.ECopyOptionItemKey.XCutLineStyle).getSelectedChoice().param, optionContext.getCopyOptionItemOf(ECopyOptionItem.ECopyOptionItemKey.XCutLineWeight).getSelectedChoice().param);
        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;
    }

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

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

        static {
            try {
                f396xec9cd424[ECopyOptionItem.ECopyOptionItemChoice.XCutLine_Dash.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
        }
    }

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