package com.indeed.proctor.store;

import org.apache.commons.lang3.builder.ToStringBuilder;

import java.time.Instant;
import java.util.Objects;

public class ChangeMetadata {
    private final String username;
    private final String password;
    private final String author;
    private final Instant timestamp;
    private final String comment;

    ChangeMetadata(final String username, final String password, final String author, final String comment) {
        this(username, password, author, Instant.now(), comment);
    }

    public ChangeMetadata(final String username, final String password, final String author, final Instant timestamp, final String comment) {
        this.username = Objects.requireNonNull(username);
        this.password = Objects.requireNonNull(password);
        this.author = Objects.requireNonNull(author);
        this.timestamp = Objects.requireNonNull(timestamp);
        this.comment = Objects.requireNonNull(comment);
    }

    public String getUsername() {
        return username;
    }

    public String getPassword() {
        return password;
    }

    public String getAuthor() {
        return author;
    }

    public Instant getTimestamp() {
        return timestamp;
    }

    public String getComment() {
        return comment;
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this)
                .append("username", username)
                .append("password", password)
                .append("author", author)
                .append("timestamp", timestamp)
                .append("comment", comment)
                .toString();
    }

    @Override
    public boolean equals(final Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        final ChangeMetadata that = (ChangeMetadata) o;
        return Objects.equals(username, that.username) &&
                Objects.equals(password, that.password) &&
                Objects.equals(author, that.author) &&
                Objects.equals(timestamp, that.timestamp) &&
                Objects.equals(comment, that.comment);
    }

    @Override
    public int hashCode() {
        return Objects.hash(username, password, author, timestamp, comment);
    }

    public static Builder builder() {
        return new Builder();
    }

    public static class Builder {
        private String username;
        private String password;
        private String author;
        private Instant timestamp;
        private String comment;

        public Builder setUsername(final String username) {
            this.username = username;
            return this;
        }

        public Builder setPassword(final String password) {
            this.password = password;
            return this;
        }

        public Builder setAuthor(final String author) {
            this.author = author;
            return this;
        }

        public Builder setUsernameAndAuthor(final String username) {
            setUsername(username);
            setAuthor(username);
            return this;
        }

        public Builder setTimestamp(final Instant timestamp) {
            this.timestamp = timestamp;
            return this;
        }

        public Builder setComment(final String comment) {
            this.comment = comment;
            return this;
        }

        public ChangeMetadata build() {
            return new ChangeMetadata(
                    username,
                    password,
                    author,
                    timestamp == null ? Instant.now() : timestamp,
                    comment);
        }
    }
}

@@ -86,16 +86,50 @@
 ilder;%0A%0A
+import javax.annotation.Nullable;%0A
 import j
@@ -146,16 +146,16 @@
 nstant;%0A
-
 import j
@@ -587,38 +587,83 @@
 etadata(
-final String username,
+%0A            @Nullable final String username,%0A            @Nullable
  final S
@@ -669,32 +669,44 @@
 String password,
+%0A           
  final String au
@@ -706,24 +706,36 @@
 ring author,
+%0A           
  final Insta
@@ -747,16 +747,28 @@
 mestamp,
+%0A           
  final S
@@ -772,32 +772,37 @@
 l String comment
+%0A    
 ) %7B%0A        this
@@ -817,39 +817,16 @@
 e = 
-Objects.requireNonNull(
 username
 );%0A 
@@ -813,33 +813,32 @@
 rname = username
-)
 ;%0A        this.p
@@ -851,39 +851,16 @@
 d = 
-Objects.requireNonNull(
 password
 );%0A 
@@ -855,17 +855,16 @@
 password
-)
 ;%0A      
@@ -1026,32 +1026,46 @@
 omment);%0A    %7D%0A%0A
+    @Nullable%0A
     public Strin
@@ -1106,32 +1106,46 @@
 sername;%0A    %7D%0A%0A
+    @Nullable%0A
     public Strin

Mark username and password nullable