package net.gotev.uploadservice;

import android.content.Context;
import android.content.Intent;
import java.util.UUID;
import net.gotev.uploadservice.UploadRequest;
/* loaded from: classes.dex */
public abstract class UploadRequest<B extends UploadRequest<B>> {
    private static final String LOG_TAG = "UploadRequest";
    protected final Context context;
    protected UploadStatusDelegate delegate;
    protected final UploadTaskParameters params;

    protected abstract Class<? extends UploadTask> getTaskClass();

    /* JADX INFO: Access modifiers changed from: protected */
    public final B self() {
        return this;
    }

    public UploadRequest(Context context, String str, String str2) throws IllegalArgumentException {
        UploadTaskParameters uploadTaskParameters = new UploadTaskParameters();
        this.params = uploadTaskParameters;
        if (context == null) {
            throw new IllegalArgumentException("Context MUST not be null!");
        }
        if (str2 == null || BuildConfig.FLAVOR.equals(str2)) {
            throw new IllegalArgumentException("Server URL cannot be null or empty");
        }
        this.context = context;
        if (str == null || str.isEmpty()) {
            Logger.debug(LOG_TAG, "null or empty upload ID. Generating it");
            uploadTaskParameters.setId(UUID.randomUUID().toString());
        } else {
            Logger.debug(LOG_TAG, "setting provided upload ID");
            uploadTaskParameters.setId(str);
        }
        uploadTaskParameters.setServerUrl(str2);
        String str3 = LOG_TAG;
        Logger.debug(str3, "Created new upload request to " + uploadTaskParameters.getServerUrl() + " with ID: " + uploadTaskParameters.getId());
    }

    public String startUpload() {
        UploadService.setUploadStatusDelegate(this.params.getId(), this.delegate);
        Intent intent = new Intent(this.context, UploadService.class);
        initializeIntent(intent);
        intent.setAction(UploadService.getActionUpload());
        this.context.startService(intent);
        return this.params.getId();
    }

    /* JADX INFO: Access modifiers changed from: protected */
    public void initializeIntent(Intent intent) {
        intent.putExtra("taskParameters", this.params);
        Class<? extends UploadTask> taskClass = getTaskClass();
        if (taskClass == null) {
            throw new RuntimeException("The request must specify a task class!");
        }
        intent.putExtra("taskClass", taskClass.getName());
    }

    public B setNotificationConfig(UploadNotificationConfig uploadNotificationConfig) {
        this.params.setNotificationConfig(uploadNotificationConfig);
        return self();
    }

    public B setAutoDeleteFilesAfterSuccessfulUpload(boolean z) {
        this.params.setAutoDeleteSuccessfullyUploadedFiles(z);
        return self();
    }

    public B setMaxRetries(int i) {
        this.params.setMaxRetries(i);
        return self();
    }

    public B setDelegate(UploadStatusDelegate uploadStatusDelegate) {
        this.delegate = uploadStatusDelegate;
        return self();
    }
}
