package epson.scan.activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;


import com.epson.iprint.prtlogger.CommonLog;
import com.epson.iprint.shared.SharedParamScan;

class ScanActivityCommonParams {
    private static final Class<? extends Activity> ESC_I1_SCAN_ACTIVITY = ScanActivity.class;
    private static final Class<? extends Activity> ESC_I2_SCAN_ACTIVITY = I2ScanActivity.class;
    private static final String PARAM_KEY_EXTERNAL_INTENT_DATA = "external-intent-data";
    private static final String PARAM_KEY_START_SCAN_AT_ACTIVITY_CHANGE = "start-scan-at-activity-change";

    ScanActivityCommonParams() {
    }

    @NonNull
    static Intent getEscIVersionChangeIntent(@NonNull Context context, int i, boolean z, @Nullable SharedParamScan sharedParamScan, @Nullable CommonLog commonLog) {
        Intent intent = new Intent(context, getScanActivityClass(i));
        intent.putExtra(PARAM_KEY_START_SCAN_AT_ACTIVITY_CHANGE, z);
        intent.putExtra(PARAM_KEY_EXTERNAL_INTENT_DATA, sharedParamScan);
        intent.putExtra(ScanActivity.PARAM_KEY_SCAN_LOG, commonLog);
        return intent;
    }

    private static Class<?> getScanActivityClass(int i) {
        if (i != 2) {
            return ESC_I1_SCAN_ACTIVITY;
        }
        return ESC_I2_SCAN_ACTIVITY;
    }

    static boolean startScanAtActivityChange(@Nullable Intent intent) {
        return intent != null && intent.getBooleanExtra(PARAM_KEY_START_SCAN_AT_ACTIVITY_CHANGE, false);
    }

    static SharedParamScan getExternalIntentData(@Nullable Intent intent) {
        if (intent == null) {
            return null;
        }
        return (SharedParamScan) intent.getSerializableExtra(PARAM_KEY_EXTERNAL_INTENT_DATA);
    }

    static CommonLog getCommonLog(@Nullable Intent intent) {
        if (intent == null) {
            return null;
        }
        return (CommonLog) intent.getSerializableExtra(ScanActivity.PARAM_KEY_SCAN_LOG);
    }
}
