package de.jeha.kame.crawler.service.api;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
 * @author jenshadlich@googlemail.com
 */
@JsonInclude(JsonInclude.Include.NON_NULL)
public class CrawlResponse {

    private final String id;
    private final String date;
    private int statusCode;
    private final Error error;

    private CrawlResponse(String id, String date, int statusCode) {
        this.id = id;
        this.date = date;
        this.statusCode = statusCode;
        this.error = null;
    }

    private CrawlResponse(String id, String date, Error error) {
        this.id = id;
        this.date = date;
        this.error = error;
    }

    @JsonProperty
    public String getId() {
        return id;
    }

    @JsonProperty
    public String getDate() {
        return date;
    }

    @JsonProperty
    public int getStatusCode() {
        return statusCode;
    }

    @JsonProperty()
    public Boolean hasError() {
        return error == null ? null : Boolean.TRUE;
    }

    @JsonProperty
    public Error getError() {
        return error;
    }

    public static CrawlResponse withSuccess(String id, String date, int statusCode) {
        return new CrawlResponse(id, date, statusCode);
    }

    public static CrawlResponse withError(String id, String date, String errorMessage) {
        return new CrawlResponse(id, date, new Error(errorMessage));
    }

    // -----------------------------------------------------------------------------------------------------------------

    public static class Error {

        private final String errorMessage;

        public Error(String errorMessage) {
            this.errorMessage = errorMessage;
        }

    }
}

@@ -335,19 +335,29 @@
 private 
+f
 in
-t
+al Integer
  statusC
@@ -714,32 +714,64 @@
 .error = error;%0A
+        this.statusCode = null;%0A
     %7D%0A%0A    @Json
@@ -938,19 +938,23 @@
  public 
-i
+I
 nt
+eger
  getStat
@@ -1015,18 +1015,16 @@
 Property
-()
 %0A    pub
@@ -1794,20 +1794,127 @@
 %0A        %7D%0A%0A
+        @JsonProperty%0A        public String getErrorMessage() %7B%0A            return errorMessage;%0A        %7D%0A
     %7D%0A%7D%0A

fix json serialization