package seedu.tasklist.model.task;


import seedu.tasklist.commons.exceptions.IllegalValueException;

/**
 * Represents a Task's comment in the task list.
 * Guarantees: immutable; is valid as declared in {@link #isValidComment(String)}
 */
public class Comment {

    public static final String MESSAGE_COMMENT_CONSTRAINTS =
            "Task comments can take any values, and it should not be blank";

    /*
     * The first character of the comment must not be a whitespace,
     * otherwise " " (a blank string) becomes a valid input.
     */
    public static final String COMMENT_VALIDATION_REGEX = "[^\\s].*";

    public final String value;

    /**
     * Validates given comment.
     *
     * @throws IllegalValueException if given comment string is invalid.
     */
    public Comment(String comment) throws IllegalValueException {
        assert comment != null;
        if (!isValidComment(comment)) {
            throw new IllegalValueException(MESSAGE_COMMENT_CONSTRAINTS);
        }
        this.value = comment;
    }

    /**
     * Returns true if a given string is a valid Task email.
     */
    public static boolean isValidComment(String test) {
        return test.matches(COMMENT_VALIDATION_REGEX);
    }

    @Override
    public String toString() {
        return value;
    }

    @Override
    public boolean equals(Object other) {
        return other == this // short circuit if same object
                || (other instanceof Comment // instanceof handles nulls
                && this.value.equals(((Comment) other).value)); // state check
    }

    @Override
    public int hashCode() {
        return value.hashCode();
    }

}

@@ -30,16 +30,44 @@
 task;%0A%0A%0A
+import java.util.Optional;%0A%0A
 import s
@@ -1055,24 +1055,587 @@
 ent;%0A    %7D%0A%0A
+    public Comment(Optional%3CString%3E comment) throws IllegalValueException %7B%0A        if (isCommentPresent(comment)) %7B%0A            String commentString = comment.get();%0A            assert commentString != null;%0A            if (!isValidComment(commentString)) %7B%0A                throw new IllegalValueException(MESSAGE_COMMENT_CONSTRAINTS);%0A            %7D%0A            this.value = commentString;%0A        %7D else %7B%0A            this.value = null;%0A        %7D%0A    %7D%0A%0A    public boolean isCommentPresent(Optional%3CString%3E comment) %7B%0A        return comment.isPresent();%0A    %7D%0A%0A
     /**%0A    

add constructor for Optional<String> in Comment