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

package io.sentry;

import java.util.concurrent.ConcurrentHashMap;
import io.sentry.vendor.gson.stream.JsonToken;
import java.io.IOException;
import java.util.Iterator;
import io.sentry.util.Objects;
import io.sentry.util.CollectionUtils;
import org.jetbrains.annotations.Nullable;
import java.util.Map;
import org.jetbrains.annotations.NotNull;
import io.sentry.protocol.SentryId;

public final class ProfileContext implements JsonUnknown, JsonSerializable
{
    public static final String TYPE = "profile";
    @NotNull
    private SentryId profilerId;
    @Nullable
    private Map<String, Object> unknown;
    
    public ProfileContext() {
        this(SentryId.EMPTY_ID);
    }
    
    public ProfileContext(@NotNull final SentryId profilerId) {
        this.profilerId = profilerId;
    }
    
    public ProfileContext(@NotNull final ProfileContext profileContext) {
        this.profilerId = profileContext.profilerId;
        final Map<String, Object> copiedUnknown = CollectionUtils.newConcurrentHashMap(profileContext.unknown);
        if (copiedUnknown != null) {
            this.unknown = copiedUnknown;
        }
    }
    
    @Override
    public boolean equals(final Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof ProfileContext)) {
            return false;
        }
        final ProfileContext that = (ProfileContext)o;
        return this.profilerId.equals(that.profilerId);
    }
    
    @Override
    public int hashCode() {
        return Objects.hash(this.profilerId);
    }
    
    @Override
    public void serialize(@NotNull final ObjectWriter writer, @NotNull final ILogger logger) throws IOException {
        writer.beginObject();
        writer.name("profiler_id").value(logger, this.profilerId);
        if (this.unknown != null) {
            for (final String key : this.unknown.keySet()) {
                final Object value = this.unknown.get(key);
                writer.name(key).value(logger, value);
            }
        }
        writer.endObject();
    }
    
    @NotNull
    public SentryId getProfilerId() {
        return this.profilerId;
    }
    
    @Nullable
    @Override
    public Map<String, Object> getUnknown() {
        return this.unknown;
    }
    
    @Override
    public void setUnknown(@Nullable final Map<String, Object> unknown) {
        this.unknown = unknown;
    }
    
    public static final class JsonKeys
    {
        public static final String PROFILER_ID = "profiler_id";
    }
    
    public static final class Deserializer implements JsonDeserializer<ProfileContext>
    {
        @NotNull
        @Override
        public ProfileContext deserialize(@NotNull final ObjectReader reader, @NotNull final ILogger logger) throws Exception {
            reader.beginObject();
            final ProfileContext data = new ProfileContext();
            Map<String, Object> unknown = null;
            while (reader.peek() == JsonToken.NAME) {
                final String nextName2;
                final String nextName = nextName2 = reader.nextName();
                switch (nextName2) {
                    case "profiler_id": {
                        final SentryId profilerId = reader.nextOrNull(logger, (JsonDeserializer<SentryId>)new SentryId.Deserializer());
                        if (profilerId != null) {
                            data.profilerId = profilerId;
                            continue;
                        }
                        continue;
                    }
                    default: {
                        if (unknown == null) {
                            unknown = new ConcurrentHashMap<String, Object>();
                        }
                        reader.nextUnknown(logger, unknown, nextName);
                        continue;
                    }
                }
            }
            data.setUnknown(unknown);
            reader.endObject();
            return data;
        }
    }
}
