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

package io.sentry;

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

final class Dsn
{
    @NotNull
    private final String projectId;
    @Nullable
    private final String path;
    @Nullable
    private final String secretKey;
    @NotNull
    private final String publicKey;
    @NotNull
    private final URI sentryUri;
    
    @NotNull
    public String getProjectId() {
        return this.projectId;
    }
    
    @Nullable
    public String getPath() {
        return this.path;
    }
    
    @Nullable
    public String getSecretKey() {
        return this.secretKey;
    }
    
    @NotNull
    public String getPublicKey() {
        return this.publicKey;
    }
    
    @NotNull
    URI getSentryUri() {
        return this.sentryUri;
    }
    
    Dsn(@Nullable final String dsn) throws IllegalArgumentException {
        try {
            Objects.requireNonNull(dsn, "The DSN is required.");
            final URI uri = new URI(dsn).normalize();
            final String scheme = uri.getScheme();
            if (!"http".equalsIgnoreCase(scheme) && !"https".equalsIgnoreCase(scheme)) {
                throw new IllegalArgumentException("Invalid DSN scheme: " + scheme);
            }
            final String userInfo = uri.getUserInfo();
            if (userInfo == null || userInfo.isEmpty()) {
                throw new IllegalArgumentException("Invalid DSN: No public key provided.");
            }
            final String[] keys = userInfo.split(":", -1);
            this.publicKey = keys[0];
            if (this.publicKey == null || this.publicKey.isEmpty()) {
                throw new IllegalArgumentException("Invalid DSN: No public key provided.");
            }
            this.secretKey = ((keys.length > 1) ? keys[1] : null);
            String uriPath = uri.getPath();
            if (uriPath.endsWith("/")) {
                uriPath = uriPath.substring(0, uriPath.length() - 1);
            }
            final int projectIdStart = uriPath.lastIndexOf("/") + 1;
            String path = uriPath.substring(0, projectIdStart);
            if (!path.endsWith("/")) {
                path += "/";
            }
            this.path = path;
            this.projectId = uriPath.substring(projectIdStart);
            if (this.projectId.isEmpty()) {
                throw new IllegalArgumentException("Invalid DSN: A Project Id is required.");
            }
            this.sentryUri = new URI(scheme, null, uri.getHost(), uri.getPort(), path + "api/" + this.projectId, null, null);
        }
        catch (final Throwable e) {
            throw new IllegalArgumentException(e);
        }
    }
}
