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

package io.sentry;

import java.util.HashMap;
import io.sentry.vendor.gson.stream.JsonToken;
import java.io.IOException;
import java.util.Iterator;
import java.util.Map;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.NotNull;

public final class SentryLogEventAttributeValue implements JsonUnknown, JsonSerializable
{
    @NotNull
    private String type;
    @Nullable
    private Object value;
    @Nullable
    private Map<String, Object> unknown;
    
    public SentryLogEventAttributeValue(@NotNull final String type, @Nullable final Object value) {
        this.type = type;
        if (value != null && type.equals("string")) {
            this.value = value.toString();
        }
        else {
            this.value = value;
        }
    }
    
    public SentryLogEventAttributeValue(@NotNull final SentryAttributeType type, @Nullable final Object value) {
        this(type.apiName(), value);
    }
    
    @NotNull
    public String getType() {
        return this.type;
    }
    
    @Nullable
    public Object getValue() {
        return this.value;
    }
    
    @Override
    public void serialize(@NotNull final ObjectWriter writer, @NotNull final ILogger logger) throws IOException {
        writer.beginObject();
        writer.name("type").value(logger, this.type);
        writer.name("value").value(logger, this.value);
        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();
    }
    
    @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 TYPE = "type";
        public static final String VALUE = "value";
    }
    
    public static final class Deserializer implements JsonDeserializer<SentryLogEventAttributeValue>
    {
        @NotNull
        @Override
        public SentryLogEventAttributeValue deserialize(@NotNull final ObjectReader reader, @NotNull final ILogger logger) throws Exception {
            Map<String, Object> unknown = null;
            String type = null;
            Object value = null;
            reader.beginObject();
            while (reader.peek() == JsonToken.NAME) {
                final String nextName2;
                final String nextName = nextName2 = reader.nextName();
                switch (nextName2) {
                    case "type": {
                        type = reader.nextStringOrNull();
                        continue;
                    }
                    case "value": {
                        value = reader.nextObjectOrNull();
                        continue;
                    }
                    default: {
                        if (unknown == null) {
                            unknown = new HashMap<String, Object>();
                        }
                        reader.nextUnknown(logger, unknown, nextName);
                        continue;
                    }
                }
            }
            reader.endObject();
            if (type == null) {
                final String message = "Missing required field \"type\"";
                final Exception exception = new IllegalStateException(message);
                logger.log(SentryLevel.ERROR, message, exception);
                throw exception;
            }
            final SentryLogEventAttributeValue logEvent = new SentryLogEventAttributeValue(type, value);
            logEvent.setUnknown(unknown);
            return logEvent;
        }
    }
}
