// 
// Decompiled by Procyon v0.6.0
// 

package io.sentry;

import java.util.Map;
import java.net.URI;
import java.util.HashMap;
import io.sentry.util.Objects;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.ApiStatus;

@ApiStatus.Experimental
public final class RequestDetailsResolver
{
    private static final String USER_AGENT = "User-Agent";
    private static final String SENTRY_AUTH = "X-Sentry-Auth";
    @NotNull
    private final Dsn dsn;
    @Nullable
    private final String sentryClientName;
    
    public RequestDetailsResolver(@NotNull final String dsn, @Nullable final String sentryClientName) {
        Objects.requireNonNull(dsn, "dsn is required");
        this.dsn = new Dsn(dsn);
        this.sentryClientName = sentryClientName;
    }
    
    @ApiStatus.Internal
    public RequestDetailsResolver(@NotNull final SentryOptions options) {
        Objects.requireNonNull(options, "options is required");
        this.dsn = options.retrieveParsedDsn();
        this.sentryClientName = options.getSentryClientName();
    }
    
    @NotNull
    public RequestDetails resolve() {
        final URI sentryUri = this.dsn.getSentryUri();
        final String envelopeUrl = sentryUri.resolve(sentryUri.getPath() + "/envelope/").toString();
        final String publicKey = this.dsn.getPublicKey();
        final String secretKey = this.dsn.getSecretKey();
        final String authHeader = "Sentry sentry_version=7,sentry_client=" + this.sentryClientName + ",sentry_key=" + publicKey + ((secretKey != null && secretKey.length() > 0) ? (",sentry_secret=" + secretKey) : "");
        final Map<String, String> headers = new HashMap<String, String>();
        headers.put("User-Agent", this.sentryClientName);
        headers.put("X-Sentry-Auth", authHeader);
        return new RequestDetails(envelopeUrl, headers);
    }
}
