package seedu.taskman.model.event;

import com.google.common.base.Objects;
import seedu.taskman.commons.exceptions.IllegalValueException;

public class Frequency {
    // TODO: write proper constrain message
    public static final String MESSAGE_FREQUENCY_CONSTRAINTS = "Placeholder for now!";
    public static final String FREQUENCY_VALIDATION_REGEX = "\\d+";

    public final Long seconds;

    public Frequency(String frequency) throws IllegalValueException {
        assert frequency != null;
        frequency = frequency.trim();
        if (!isValidFrequency(frequency)) {
            throw new IllegalValueException(MESSAGE_FREQUENCY_CONSTRAINTS);
        }
        this.seconds = Long.valueOf(frequency);
    }

    public static boolean isValidFrequency(String test) {
        // TODO: write proper validation

        return test.matches(FREQUENCY_VALIDATION_REGEX);
    }

    @Override
    public String toString() {
        return String.valueOf(seconds);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Frequency frequency = (Frequency) o;
        return Objects.equal(seconds, frequency.seconds);
    }

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

@@ -174,38 +174,77 @@
 DO: 
-write proper constrain message
+check for overflow of seconds because current validation allows years
 %0A   
@@ -308,28 +308,105 @@
  = %22
-Place
+Task frequency s
 ho
+u
 ld
-er for now!
+ only contain frequency and unit of time in the format: %3Cnumber%3E%3Ch/d/w/m/y%3E.
 %22;%0A 
@@ -469,12 +469,46 @@
  = %22
-%5C%5Cd+
+(%5B1-9%5D%7C(%5B1-9%5D+%5B0-9%5D*%5B0-9%5D))(h%7Cd%7Cw%7Cm%7Cy)
 %22;%0A%0A
@@ -928,20 +928,17 @@
 ) %7B%0A    
-    
+%09
 // TODO:
@@ -942,32 +942,40 @@
 DO: 
-write proper validation%0A
+improve on validation, see above
 %0A   

Add FREQUENCY_VALIDATION_REGEX