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

package io.sentry;

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

public final class SentryLogEvent implements JsonUnknown, JsonSerializable
{
    @NotNull
    private SentryId traceId;
    @NotNull
    private Double timestamp;
    @NotNull
    private String body;
    @NotNull
    private SentryLogLevel level;
    @Nullable
    private Integer severityNumber;
    @Nullable
    private Map<String, SentryLogEventAttributeValue> attributes;
    @Nullable
    private Map<String, Object> unknown;
    
    public SentryLogEvent(@NotNull final SentryId traceId, @NotNull final SentryDate timestamp, @NotNull final String body, @NotNull final SentryLogLevel level) {
        this(traceId, DateUtils.nanosToSeconds(timestamp.nanoTimestamp()), body, level);
    }
    
    public SentryLogEvent(@NotNull final SentryId traceId, @NotNull final Double timestamp, @NotNull final String body, @NotNull final SentryLogLevel level) {
        this.traceId = traceId;
        this.timestamp = timestamp;
        this.body = body;
        this.level = level;
    }
    
    @NotNull
    public Double getTimestamp() {
        return this.timestamp;
    }
    
    public void setTimestamp(@NotNull final Double timestamp) {
        this.timestamp = timestamp;
    }
    
    @NotNull
    public String getBody() {
        return this.body;
    }
    
    public void setBody(@NotNull final String body) {
        this.body = body;
    }
    
    @NotNull
    public SentryLogLevel getLevel() {
        return this.level;
    }
    
    public void setLevel(@NotNull final SentryLogLevel level) {
        this.level = level;
    }
    
    @Nullable
    public Map<String, SentryLogEventAttributeValue> getAttributes() {
        return this.attributes;
    }
    
    public void setAttributes(@Nullable final Map<String, SentryLogEventAttributeValue> attributes) {
        this.attributes = attributes;
    }
    
    public void setAttribute(@Nullable final String key, @Nullable final SentryLogEventAttributeValue value) {
        if (key == null) {
            return;
        }
        if (this.attributes == null) {
            this.attributes = new HashMap<String, SentryLogEventAttributeValue>();
        }
        this.attributes.put(key, value);
    }
    
    @Nullable
    public Integer getSeverityNumber() {
        return this.severityNumber;
    }
    
    public void setSeverityNumber(@Nullable final Integer severityNumber) {
        this.severityNumber = severityNumber;
    }
    
    @Override
    public void serialize(@NotNull final ObjectWriter writer, @NotNull final ILogger logger) throws IOException {
        writer.beginObject();
        writer.name("timestamp").value(logger, DateUtils.doubleToBigDecimal(this.timestamp));
        writer.name("trace_id").value(logger, this.traceId);
        writer.name("body").value(this.body);
        writer.name("level").value(logger, this.level);
        if (this.severityNumber != null) {
            writer.name("severity_number").value(logger, this.severityNumber);
        }
        if (this.attributes != null) {
            writer.name("attributes").value(logger, this.attributes);
        }
        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 TIMESTAMP = "timestamp";
        public static final String TRACE_ID = "trace_id";
        public static final String LEVEL = "level";
        public static final String SEVERITY_NUMBER = "severity_number";
        public static final String BODY = "body";
        public static final String ATTRIBUTES = "attributes";
    }
    
    public static final class Deserializer implements JsonDeserializer<SentryLogEvent>
    {
        @NotNull
        @Override
        public SentryLogEvent deserialize(@NotNull final ObjectReader reader, @NotNull final ILogger logger) throws Exception {
            Map<String, Object> unknown = null;
            SentryId traceId = null;
            Double timestamp = null;
            String body = null;
            SentryLogLevel level = null;
            Integer severityNumber = null;
            Map<String, SentryLogEventAttributeValue> attributes = null;
            reader.beginObject();
            while (reader.peek() == JsonToken.NAME) {
                final String nextName2;
                final String nextName = nextName2 = reader.nextName();
                switch (nextName2) {
                    case "trace_id": {
                        traceId = reader.nextOrNull(logger, (JsonDeserializer<SentryId>)new SentryId.Deserializer());
                        continue;
                    }
                    case "timestamp": {
                        timestamp = reader.nextDoubleOrNull();
                        continue;
                    }
                    case "body": {
                        body = reader.nextStringOrNull();
                        continue;
                    }
                    case "level": {
                        level = reader.nextOrNull(logger, (JsonDeserializer<SentryLogLevel>)new SentryLogLevel.Deserializer());
                        continue;
                    }
                    case "severity_number": {
                        severityNumber = reader.nextIntegerOrNull();
                        continue;
                    }
                    case "attributes": {
                        attributes = reader.nextMapOrNull(logger, (JsonDeserializer<SentryLogEventAttributeValue>)new SentryLogEventAttributeValue.Deserializer());
                        continue;
                    }
                    default: {
                        if (unknown == null) {
                            unknown = new HashMap<String, Object>();
                        }
                        reader.nextUnknown(logger, unknown, nextName);
                        continue;
                    }
                }
            }
            reader.endObject();
            if (traceId == null) {
                final String message = "Missing required field \"trace_id\"";
                final Exception exception = new IllegalStateException(message);
                logger.log(SentryLevel.ERROR, message, exception);
                throw exception;
            }
            if (timestamp == null) {
                final String message = "Missing required field \"timestamp\"";
                final Exception exception = new IllegalStateException(message);
                logger.log(SentryLevel.ERROR, message, exception);
                throw exception;
            }
            if (body == null) {
                final String message = "Missing required field \"body\"";
                final Exception exception = new IllegalStateException(message);
                logger.log(SentryLevel.ERROR, message, exception);
                throw exception;
            }
            if (level == null) {
                final String message = "Missing required field \"level\"";
                final Exception exception = new IllegalStateException(message);
                logger.log(SentryLevel.ERROR, message, exception);
                throw exception;
            }
            final SentryLogEvent logEvent = new SentryLogEvent(traceId, timestamp, body, level);
            logEvent.setAttributes(attributes);
            logEvent.setSeverityNumber(severityNumber);
            logEvent.setUnknown(unknown);
            return logEvent;
        }
    }
}
