package epson.print.copy.Component.ecopycomponent;

import android.os.AsyncTask;
import epson.print.copy.Component.ecopycomponent.ECopyComponent;
import epson.print.copy.Component.eremoteoperation.ERemoteCopyPhoto;
import epson.print.copy.Component.eremoteoperation.ERemoteOperation;
import java.util.ArrayList;

class RemoteCopyPhotoGetOptionTask extends AsyncTask<Void, Void, Result> implements ECopyComponent.ITask {
    String clientID;
    ECopyComponent.ICopyOptionContextListener contextListener;
    ECopyComponent.ECopyType copyType;
    ERemoteCopyPhoto operation = new ERemoteCopyPhoto();
    ECopyOptionContext optionContext;
    ECopyComponent.ICopySystemSettings systemSettings;

    class Result {
        ECopyComponent.ECopyType copyType;
        ECopyComponent.ICopyOptionContextListener.ContextCreationError error;
        ECopyOptionContext optionContext;

        Result() {
        }
    }

    public RemoteCopyPhotoGetOptionTask(ECopyComponent.ECopyType eCopyType, ECopyComponent.ICopyOptionContextListener iCopyOptionContextListener) {
        this.copyType = eCopyType;
        this.contextListener = iCopyOptionContextListener;
    }

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

    public void setOptionContext(ECopyOptionContext eCopyOptionContext) {
        this.optionContext = eCopyOptionContext;
    }

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

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

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

    protected Result doInBackground(Void... voidArr) {
        this.operation.setHostIP(this.systemSettings.getPrinterIPAddress());
        Result result = new Result();
        result.copyType = this.copyType;
        final ERemoteCopyPhoto.ERemoteCopyPhotoOptionResult selectableOptions = this.operation.getSelectableOptions();
        if (!selectableOptions.success()) {
            if (selectableOptions.isNull(ERemoteOperation.ERemoteParam.success)) {
                result.error = ECopyComponent.ICopyOptionContextListener.ContextCreationError.ErrorCommunication;
            } else {
                result.error = ECopyComponent.ICopyOptionContextListener.ContextCreationError.Error;
            }
            return result;
        }
        ERemoteCopyPhoto.ERemoteCopyPhotoOptionResult options = this.operation.getOptions(new ERemoteCopyPhoto.IRemoteCopyPhotoOptionsParameter() {
            public boolean default_as_fixed() {
                return true;
            }

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

            public ERemoteOperation.ERemoteParam layout() {
                return selectableOptions.parameter_default(ERemoteOperation.ERemoteParam.layout);
            }

            public ERemoteOperation.ERemoteParam print_media_type() {
                return selectableOptions.parameter_default(ERemoteOperation.ERemoteParam.print_media_type);
            }

            public ERemoteOperation.ERemoteParam print_media_size() {
                return selectableOptions.parameter_default(ERemoteOperation.ERemoteParam.print_media_size);
            }

            public ERemoteOperation.ERemoteParam print_quality() {
                return selectableOptions.parameter_default(ERemoteOperation.ERemoteParam.print_quality);
            }

            public ERemoteOperation.ERemoteParam print_media_source() {
                return selectableOptions.parameter_default(ERemoteOperation.ERemoteParam.print_media_source);
            }

            public ERemoteOperation.ERemoteParam x_apf() {
                return selectableOptions.parameter_default(ERemoteOperation.ERemoteParam.x_apf);
            }

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

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

            public ArrayList<ERemoteOperation.ERemoteParam> priority_order() {
                ArrayList<ERemoteOperation.ERemoteParam> arrayList = new ArrayList<>();
                arrayList.add(ERemoteOperation.ERemoteParam.layout);
                arrayList.add(ERemoteOperation.ERemoteParam.print_media_size);
                arrayList.add(ERemoteOperation.ERemoteParam.print_media_type);
                arrayList.add(ERemoteOperation.ERemoteParam.x_apf);
                arrayList.add(ERemoteOperation.ERemoteParam.print_quality);
                arrayList.add(ERemoteOperation.ERemoteParam.print_media_source);
                return arrayList;
            }
        });
        if (options.success()) {
            result.optionContext = new ECopyOptionContext(this.copyType);
            result.optionContext.setCopyOptionsResult(options);
            result.optionContext.add(ECopyOptionItem.createOptionItem(ERemoteOperation.ERemoteParam.print_media_size, options));
            result.optionContext.add(ECopyOptionItem.createOptionItem(ERemoteOperation.ERemoteParam.print_media_type, options));
            result.optionContext.add(ECopyOptionItem.createOptionItem(ERemoteOperation.ERemoteParam.print_media_source, options));
            result.optionContext.add(ECopyOptionItem.createOptionItem(ERemoteOperation.ERemoteParam.print_quality, options));
            result.optionContext.add(ECopyOptionItem.createOptionItem(ERemoteOperation.ERemoteParam.x_apf, options));
            result.optionContext.add(ECopyOptionItem.createOptionItem(ERemoteOperation.ERemoteParam.x_borderless, options));
            result.optionContext.add(ECopyOptionItem.createLocalOptionItem(ERemoteOperation.ERemoteParam.x_color_restoration, options));
            result.optionContext.add(ECopyOptionItem.createLocalOptionItem(ERemoteOperation.ERemoteParam.print_x_bleed, options));
            result.optionContext.add(ECopyOptionItem.createLocalOptionItem(ERemoteOperation.ERemoteParam.color_effects_type, options));
        } else if (options.isNull(ERemoteOperation.ERemoteParam.success)) {
            result.error = ECopyComponent.ICopyOptionContextListener.ContextCreationError.ErrorCommunication;
        } else {
            result.error = ECopyComponent.ICopyOptionContextListener.ContextCreationError.Error;
        }
        return result;
    }

    protected void onPostExecute(Result result) {
        this.contextListener.onCopyOptionContextCreated(result.copyType, result.optionContext, result.error);
    }
}
