// 
// 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 MonitorConfig implements JsonUnknown, JsonSerializable
{
    @NotNull
    private MonitorSchedule schedule;
    @Nullable
    private Long checkinMargin;
    @Nullable
    private Long maxRuntime;
    @Nullable
    private String timezone;
    @Nullable
    private Long failureIssueThreshold;
    @Nullable
    private Long recoveryThreshold;
    @Nullable
    private Map<String, Object> unknown;
    
    public MonitorConfig(@NotNull final MonitorSchedule schedule) {
        this.schedule = schedule;
        final SentryOptions.Cron defaultCron = ScopesAdapter.getInstance().getOptions().getCron();
        if (defaultCron != null) {
            this.checkinMargin = defaultCron.getDefaultCheckinMargin();
            this.maxRuntime = defaultCron.getDefaultMaxRuntime();
            this.timezone = defaultCron.getDefaultTimezone();
            this.failureIssueThreshold = defaultCron.getDefaultFailureIssueThreshold();
            this.recoveryThreshold = defaultCron.getDefaultRecoveryThreshold();
        }
    }
    
    @NotNull
    public MonitorSchedule getSchedule() {
        return this.schedule;
    }
    
    public void setSchedule(@NotNull final MonitorSchedule schedule) {
        this.schedule = schedule;
    }
    
    @Nullable
    public Long getCheckinMargin() {
        return this.checkinMargin;
    }
    
    public void setCheckinMargin(@Nullable final Long checkinMargin) {
        this.checkinMargin = checkinMargin;
    }
    
    @Nullable
    public Long getMaxRuntime() {
        return this.maxRuntime;
    }
    
    public void setMaxRuntime(@Nullable final Long maxRuntime) {
        this.maxRuntime = maxRuntime;
    }
    
    @Nullable
    public String getTimezone() {
        return this.timezone;
    }
    
    public void setTimezone(@Nullable final String timezone) {
        this.timezone = timezone;
    }
    
    @Nullable
    public Long getFailureIssueThreshold() {
        return this.failureIssueThreshold;
    }
    
    public void setFailureIssueThreshold(@Nullable final Long failureIssueThreshold) {
        this.failureIssueThreshold = failureIssueThreshold;
    }
    
    @Nullable
    public Long getRecoveryThreshold() {
        return this.recoveryThreshold;
    }
    
    public void setRecoveryThreshold(@Nullable final Long recoveryThreshold) {
        this.recoveryThreshold = recoveryThreshold;
    }
    
    @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("schedule");
        this.schedule.serialize(writer, logger);
        if (this.checkinMargin != null) {
            writer.name("checkin_margin").value(this.checkinMargin);
        }
        if (this.maxRuntime != null) {
            writer.name("max_runtime").value(this.maxRuntime);
        }
        if (this.timezone != null) {
            writer.name("timezone").value(this.timezone);
        }
        if (this.failureIssueThreshold != null) {
            writer.name("failure_issue_threshold").value(this.failureIssueThreshold);
        }
        if (this.recoveryThreshold != null) {
            writer.name("recovery_threshold").value(this.recoveryThreshold);
        }
        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 SCHEDULE = "schedule";
        public static final String CHECKIN_MARGIN = "checkin_margin";
        public static final String MAX_RUNTIME = "max_runtime";
        public static final String TIMEZONE = "timezone";
        public static final String FAILURE_ISSUE_THRESHOLD = "failure_issue_threshold";
        public static final String RECOVERY_THRESHOLD = "recovery_threshold";
    }
    
    public static final class Deserializer implements JsonDeserializer<MonitorConfig>
    {
        @NotNull
        @Override
        public MonitorConfig deserialize(@NotNull final ObjectReader reader, @NotNull final ILogger logger) throws Exception {
            MonitorSchedule schedule = null;
            Long checkinMargin = null;
            Long maxRuntime = null;
            String timezone = null;
            Long failureIssureThreshold = null;
            Long recoveryThreshold = 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 "schedule": {
                        schedule = new MonitorSchedule.Deserializer().deserialize(reader, logger);
                        continue;
                    }
                    case "checkin_margin": {
                        checkinMargin = reader.nextLongOrNull();
                        continue;
                    }
                    case "max_runtime": {
                        maxRuntime = reader.nextLongOrNull();
                        continue;
                    }
                    case "timezone": {
                        timezone = reader.nextStringOrNull();
                        continue;
                    }
                    case "failure_issue_threshold": {
                        failureIssureThreshold = reader.nextLongOrNull();
                        continue;
                    }
                    case "recovery_threshold": {
                        recoveryThreshold = reader.nextLongOrNull();
                        continue;
                    }
                    default: {
                        if (unknown == null) {
                            unknown = new HashMap<String, Object>();
                        }
                        reader.nextUnknown(logger, unknown, nextName);
                        continue;
                    }
                }
            }
            reader.endObject();
            if (schedule == null) {
                final String message = "Missing required field \"schedule\"";
                final Exception exception = new IllegalStateException(message);
                logger.log(SentryLevel.ERROR, message, exception);
                throw exception;
            }
            final MonitorConfig monitorConfig = new MonitorConfig(schedule);
            monitorConfig.setCheckinMargin(checkinMargin);
            monitorConfig.setMaxRuntime(maxRuntime);
            monitorConfig.setTimezone(timezone);
            monitorConfig.setFailureIssueThreshold(failureIssureThreshold);
            monitorConfig.setRecoveryThreshold(recoveryThreshold);
            monitorConfig.setUnknown(unknown);
            return monitorConfig;
        }
    }
}
