package net.frozenorb.apiv3.model; import lombok.Getter; import lombok.ToString; import net.frozenorb.apiv3.accessor.Users; import org.bson.Document; import java.time.Instant; import java.util.Map; import java.util.UUID; @ToString public final class User extends BaseModel { @Getter private UUID id; @Getter private String lastName; @Getter private Map aliases; @Getter private String otpCode; @Getter private String password; @Getter private String passwordSalt; @Getter private String email; @Getter private int phoneNumber; @Getter private String lastSeenOn; @Getter private Instant lastSeenAt; @Getter private Instant firstSeen; public User(Document json) { super(Users.COLLECTION_NAME); this.id = UUID.fromString(json.getString("_id")); this.lastName = json.getString("lastName"); this.aliases = (Map) json.get("aliases"); this.otpCode = json.getString("otpCode"); this.password = json.getString("password"); this.passwordSalt = json.getString("passwordSalt"); this.email = json.getString("email"); this.phoneNumber = json.getInteger("phoneNumber"); this.lastSeenOn = json.getString("lastSeenOn"); this.lastSeenAt = (Instant) json.get("lastSeenAt"); this.firstSeen = (Instant) json.get("firstSeen"); setId(id.toString()); } public Document toLiteJson() { Document json = new Document(); json.put("id", id.toString()); json.put("lastName", lastName); json.put("email", email); json.put("phoneNumber", phoneNumber); json.put("lastSeenOn", lastSeenOn); json.put("lastSeenAt", lastSeenAt.toString()); json.put("firstSeen", firstSeen.toString()); return json; } public Document toFullJson() { Document json = toLiteJson(); json.put("aliases", aliases); return json; } }