package pothole.management.api.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import org.jongo.marshall.jackson.oid.Id;
import org.jongo.marshall.jackson.oid.ObjectId;

import java.text.SimpleDateFormat;
import java.util.Date;

@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class Pothole {
    @Id @ObjectId
    private String key;

    private String location;
    Date dateReported;

    //Todo: Figure out how to get this to work if fixedDate is null
    @JsonIgnore
    Date fixedDate;

    public Pothole(String location){
        this.location = location;
        this.dateReported = new Date();
        this.fixedDate = new Date();
    }

    //Introducing the dummy constructor
    public Pothole() {
        this.dateReported = new Date();
        this.fixedDate = null;
    }

    public String getKey(){
        return key;
    }

    public Pothole setKey(final String key){
        this.key = key;
        return this;
    }

    public String getLocation(){
        return location;
    }

    public Pothole setLocation(final String location){
        this.location = location;
        return this;
    }

    public String getDateReported(){
        SimpleDateFormat dt = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz");
        return dt.format(this.dateReported);
    }

    public Pothole setDateReported(final Date dateReported){
        this.dateReported = dateReported;
        return this;
    }

    public String getFixedDate(){
        SimpleDateFormat dt = this.dateFormat();
        return dt.format(this.fixedDate);
    }

    public Pothole setFixedDate(final Date fixedDate){
        this.fixedDate = fixedDate;
        return this;
    }

    @Override
    public String toString(){
        String str = null;
        try {
            ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
            str = ow.writeValueAsString(this);
        } catch (JsonProcessingException ex){
            System.out.println("-- There was an error parsing json. --");
            System.out.println(ex.toString());
        }

        return str;
    }

    private static SimpleDateFormat dateFormat (){
        return new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz");
    }
}

@@ -617,111 +617,25 @@
 ed;%0A
-%0A
     
-//Todo: Figure out how to get this to work if fixedDate is null%0A    @JsonIgnore%0A    Date
+Boolean
  fixed
-Date
 ;%0A%0A 
@@ -766,56 +766,31 @@
 ixed
-Date = new Date();%0A    %7D%0A%0A    //Introducing the 
+ = false;%0A    %7D%0A%0A    //
 dumm
@@ -884,20 +884,16 @@
 is.fixed
-Date
  = null;
@@ -1546,30 +1546,31 @@
 %0A    public 
-String
+Boolean
  getFixedDat
@@ -1566,20 +1566,16 @@
 getFixed
-Date
 ()%7B%0A    
@@ -1582,74 +1582,15 @@
     
-SimpleDateFormat dt = this.dateFormat();%0A        return dt.format(
+return 
 this
@@ -1595,21 +1595,16 @@
 is.fixed
-Date)
 ;%0A    %7D%0A
@@ -1635,33 +1635,28 @@
 ixed
-Date
 (final 
-Date
+Boolean
  fixed
-Date
 )%7B%0A 
@@ -1676,20 +1676,16 @@
 ixed
-Date
  = fixed
 Date
@@ -1680,20 +1680,16 @@
  = fixed
-Date
 ;%0A      

change fixed to a boolean