// 
// 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 org.jetbrains.annotations.ApiStatus;
import java.util.Map;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.NotNull;

public final class MonitorSchedule implements JsonUnknown, JsonSerializable
{
    @NotNull
    private String type;
    @NotNull
    private String value;
    @Nullable
    private String unit;
    @Nullable
    private Map<String, Object> unknown;
    
    @NotNull
    public static MonitorSchedule crontab(@NotNull final String value) {
        return new MonitorSchedule(MonitorScheduleType.CRONTAB.apiName(), value, null);
    }
    
    @NotNull
    public static MonitorSchedule interval(@NotNull final Integer value, @NotNull final MonitorScheduleUnit unit) {
        return new MonitorSchedule(MonitorScheduleType.INTERVAL.apiName(), value.toString(), unit.apiName());
    }
    
    @ApiStatus.Internal
    public MonitorSchedule(@NotNull final String type, @NotNull final String value, @Nullable final String unit) {
        this.type = type;
        this.value = value;
        this.unit = unit;
    }
    
    @NotNull
    public String getType() {
        return this.type;
    }
    
    public void setType(@NotNull final String type) {
        this.type = type;
    }
    
    @NotNull
    public String getValue() {
        return this.value;
    }
    
    public void setValue(@NotNull final String value) {
        this.value = value;
    }
    
    public void setValue(@NotNull final Integer value) {
        this.value = value.toString();
    }
    
    @Nullable
    public String getUnit() {
        return this.unit;
    }
    
    public void setUnit(@Nullable final String unit) {
        this.unit = unit;
    }
    
    public void setUnit(@Nullable final MonitorScheduleUnit unit) {
        this.unit = ((unit == null) ? null : unit.apiName());
    }
    
    @Nullable
    @Override
    public Map<String, Object> getUnknown() {
        return this.unknown;
    }
    
    @Override
    public void setUnknown(@Nullable final Map<String, Object> unknown) {
        this.unknown = unknown;
    }
    
    @Override
    public void serialize(@NotNull final ObjectWriter writer, @NotNull final ILogger logger) throws IOException {
        writer.beginObject();
        writer.name("type").value(this.type);
        if (MonitorScheduleType.INTERVAL.apiName().equalsIgnoreCase(this.type)) {
            try {
                writer.name("value").value(Integer.valueOf(this.value));
            }
            catch (final Throwable t) {
                logger.log(SentryLevel.ERROR, "Unable to serialize monitor schedule value: %s", this.value);
            }
        }
        else {
            writer.name("value").value(this.value);
        }
        if (this.unit != null) {
            writer.name("unit").value(this.unit);
        }
        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();
    }
    
    public static final class JsonKeys
    {
        public static final String TYPE = "type";
        public static final String VALUE = "value";
        public static final String UNIT = "unit";
    }
    
    public static final class Deserializer implements JsonDeserializer<MonitorSchedule>
    {
        @NotNull
        @Override
        public MonitorSchedule deserialize(@NotNull final ObjectReader reader, @NotNull final ILogger logger) throws Exception {
            String type = null;
            String value = null;
            String unit = null;
            Map<String, Object> unknown = 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.nextStringOrNull();
                        continue;
                    }
                    case "unit": {
                        unit = reader.nextStringOrNull();
                        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;
            }
            if (value == null) {
                final String message = "Missing required field \"value\"";
                final Exception exception = new IllegalStateException(message);
                logger.log(SentryLevel.ERROR, message, exception);
                throw exception;
            }
            final MonitorSchedule monitorSchedule = new MonitorSchedule(type, value, unit);
            monitorSchedule.setUnknown(unknown);
            return monitorSchedule;
        }
    }
}
