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

package io.sentry.protocol;

import io.sentry.vendor.gson.stream.JsonToken;
import io.sentry.ObjectReader;
import io.sentry.JsonDeserializer;
import java.io.IOException;
import io.sentry.ILogger;
import io.sentry.ObjectWriter;
import io.sentry.util.Objects;
import java.util.Iterator;
import io.sentry.SentryLevel;
import java.util.concurrent.ConcurrentHashMap;
import io.sentry.SentryOptions;
import io.sentry.util.CollectionUtils;
import org.jetbrains.annotations.NotNull;
import java.util.Map;
import org.jetbrains.annotations.Nullable;
import io.sentry.JsonSerializable;
import io.sentry.JsonUnknown;

public final class User implements JsonUnknown, JsonSerializable
{
    @Nullable
    private String email;
    @Nullable
    private String id;
    @Nullable
    private String username;
    @Nullable
    private String ipAddress;
    @Deprecated
    @Nullable
    private String name;
    @Nullable
    private Geo geo;
    @Nullable
    private Map<String, String> data;
    @Nullable
    private Map<String, Object> unknown;
    
    public User() {
    }
    
    public User(@NotNull final User user) {
        this.email = user.email;
        this.username = user.username;
        this.id = user.id;
        this.ipAddress = user.ipAddress;
        this.name = user.name;
        this.geo = user.geo;
        this.data = CollectionUtils.newConcurrentHashMap(user.data);
        this.unknown = CollectionUtils.newConcurrentHashMap(user.unknown);
    }
    
    public static User fromMap(@NotNull final Map<String, Object> map, @NotNull final SentryOptions options) {
        final User user = new User();
        Map<String, Object> unknown = null;
        for (final Map.Entry<String, Object> entry : map.entrySet()) {
            final Object value = entry.getValue();
            final String s = entry.getKey();
            switch (s) {
                case "email": {
                    user.email = ((value instanceof String) ? ((String)value) : null);
                    continue;
                }
                case "id": {
                    user.id = ((value instanceof String) ? ((String)value) : null);
                    continue;
                }
                case "username": {
                    user.username = ((value instanceof String) ? ((String)value) : null);
                    continue;
                }
                case "ip_address": {
                    user.ipAddress = ((value instanceof String) ? ((String)value) : null);
                    continue;
                }
                case "name": {
                    user.name = ((value instanceof String) ? ((String)value) : null);
                    continue;
                }
                case "geo": {
                    final Map<Object, Object> geo = (value instanceof Map) ? ((Map)value) : null;
                    if (geo != null) {
                        final ConcurrentHashMap<String, Object> geoData = new ConcurrentHashMap<String, Object>();
                        for (final Map.Entry<Object, Object> geoEntry : geo.entrySet()) {
                            if (geoEntry.getKey() instanceof String && geoEntry.getValue() != null) {
                                geoData.put(geoEntry.getKey(), geoEntry.getValue());
                            }
                            else {
                                options.getLogger().log(SentryLevel.WARNING, "Invalid key type in gep map.", new Object[0]);
                            }
                        }
                        user.geo = Geo.fromMap(geoData);
                        continue;
                    }
                    continue;
                }
                case "data": {
                    final Map<Object, Object> data = (value instanceof Map) ? ((Map)value) : null;
                    if (data != null) {
                        final ConcurrentHashMap<String, String> userData = new ConcurrentHashMap<String, String>();
                        for (final Map.Entry<Object, Object> dataEntry : data.entrySet()) {
                            if (dataEntry.getKey() instanceof String && dataEntry.getValue() != null) {
                                userData.put(dataEntry.getKey(), dataEntry.getValue().toString());
                            }
                            else {
                                options.getLogger().log(SentryLevel.WARNING, "Invalid key or null value in data map.", new Object[0]);
                            }
                        }
                        user.data = userData;
                        continue;
                    }
                    continue;
                }
                default: {
                    if (unknown == null) {
                        unknown = new ConcurrentHashMap<String, Object>();
                    }
                    unknown.put(entry.getKey(), entry.getValue());
                    continue;
                }
            }
        }
        user.unknown = unknown;
        return user;
    }
    
    @Nullable
    public String getEmail() {
        return this.email;
    }
    
    public void setEmail(@Nullable final String email) {
        this.email = email;
    }
    
    @Nullable
    public String getId() {
        return this.id;
    }
    
    public void setId(@Nullable final String id) {
        this.id = id;
    }
    
    @Nullable
    public String getUsername() {
        return this.username;
    }
    
    public void setUsername(@Nullable final String username) {
        this.username = username;
    }
    
    @Nullable
    public String getIpAddress() {
        return this.ipAddress;
    }
    
    public void setIpAddress(@Nullable final String ipAddress) {
        this.ipAddress = ipAddress;
    }
    
    @Deprecated
    @Nullable
    public String getName() {
        return this.name;
    }
    
    @Deprecated
    public void setName(@Nullable final String name) {
        this.name = name;
    }
    
    @Nullable
    public Geo getGeo() {
        return this.geo;
    }
    
    public void setGeo(@Nullable final Geo geo) {
        this.geo = geo;
    }
    
    @Nullable
    public Map<String, String> getData() {
        return this.data;
    }
    
    public void setData(@Nullable final Map<String, String> data) {
        this.data = CollectionUtils.newConcurrentHashMap(data);
    }
    
    @Override
    public boolean equals(final Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || this.getClass() != o.getClass()) {
            return false;
        }
        final User user = (User)o;
        return Objects.equals(this.email, user.email) && Objects.equals(this.id, user.id) && Objects.equals(this.username, user.username) && Objects.equals(this.ipAddress, user.ipAddress);
    }
    
    @Override
    public int hashCode() {
        return Objects.hash(this.email, this.id, this.username, this.ipAddress);
    }
    
    @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();
        if (this.email != null) {
            writer.name("email").value(this.email);
        }
        if (this.id != null) {
            writer.name("id").value(this.id);
        }
        if (this.username != null) {
            writer.name("username").value(this.username);
        }
        if (this.ipAddress != null) {
            writer.name("ip_address").value(this.ipAddress);
        }
        if (this.name != null) {
            writer.name("name").value(this.name);
        }
        if (this.geo != null) {
            writer.name("geo");
            this.geo.serialize(writer, logger);
        }
        if (this.data != null) {
            writer.name("data").value(logger, this.data);
        }
        if (this.unknown != null) {
            for (final String key : this.unknown.keySet()) {
                final Object value = this.unknown.get(key);
                writer.name(key);
                writer.value(logger, value);
            }
        }
        writer.endObject();
    }
    
    public static final class JsonKeys
    {
        public static final String EMAIL = "email";
        public static final String ID = "id";
        public static final String USERNAME = "username";
        public static final String IP_ADDRESS = "ip_address";
        public static final String NAME = "name";
        public static final String GEO = "geo";
        public static final String DATA = "data";
    }
    
    public static final class Deserializer implements JsonDeserializer<User>
    {
        @NotNull
        @Override
        public User deserialize(@NotNull final ObjectReader reader, @NotNull final ILogger logger) throws Exception {
            reader.beginObject();
            final User user = new User();
            Map<String, Object> unknown = null;
            while (reader.peek() == JsonToken.NAME) {
                final String nextName2;
                final String nextName = nextName2 = reader.nextName();
                switch (nextName2) {
                    case "email": {
                        user.email = reader.nextStringOrNull();
                        continue;
                    }
                    case "id": {
                        user.id = reader.nextStringOrNull();
                        continue;
                    }
                    case "username": {
                        user.username = reader.nextStringOrNull();
                        continue;
                    }
                    case "ip_address": {
                        user.ipAddress = reader.nextStringOrNull();
                        continue;
                    }
                    case "name": {
                        user.name = reader.nextStringOrNull();
                        continue;
                    }
                    case "geo": {
                        user.geo = new Geo.Deserializer().deserialize(reader, logger);
                        continue;
                    }
                    case "data": {
                        user.data = (Map<String, String>)CollectionUtils.newConcurrentHashMap((Map<Object, Object>)reader.nextObjectOrNull());
                        continue;
                    }
                    default: {
                        if (unknown == null) {
                            unknown = new ConcurrentHashMap<String, Object>();
                        }
                        reader.nextUnknown(logger, unknown, nextName);
                        continue;
                    }
                }
            }
            user.setUnknown(unknown);
            reader.endObject();
            return user;
        }
    }
}
