package controllers.api;

import controllers.App;
import play.mvc.Result;
import play.mvc.Results;
import uk.gov.openregister.domain.Record;
import uk.gov.openregister.domain.RecordVersionInfo;

import java.util.List;
import java.util.Optional;

import static play.mvc.Results.ok;
import static play.mvc.Results.status;

public class HtmlRepresentation implements Representation {
    @Override
    public Result toResponse(int status, String message) {
        return toHtmlResponse(status, message);
    }

    @Override
    public Result toListOfRecords(List<Record> records) {
        return ok(views.html.entries.render(App.instance.register.fields(), records));
    }

    @Override
    public Result toRecord(Optional<Record> recordO, List<RecordVersionInfo> history) {
        return recordO.map(record ->
                ok(views.html.entry.render(App.instance.register.fields(), record, history)))
                .orElse(toHtmlResponse(404, "Entry not found"));
    }

    private static Results.Status toHtmlResponse(int status, String message) {
        return status(status, views.html.error.render(message));
    }


    public static Representation instance = new HtmlRepresentation();
}

@@ -71,33 +71,8 @@
 lt;%0A
-import play.mvc.Results;%0A
 impo
@@ -109,16 +109,16 @@
 Record;%0A
+
 import u
@@ -441,39 +441,55 @@
 urn 
-toHtmlResponse(status, 
+status(status, views.html.error.render(
 message)
 ;%0A  
@@ -484,16 +484,17 @@
 message)
+)
 ;%0A    %7D%0A
@@ -814,16 +814,25 @@
         
+ (Result)
  ok(view
@@ -928,20 +928,16 @@
 rElse(to
-Html
 Response
@@ -974,160 +974,8 @@
  %7D%0A%0A
-    private static Results.Status toHtmlResponse(int status, String message) %7B%0A        return status(status, views.html.error.render(message));%0A    %7D%0A%0A%0A
     

Simplify HtmlRepresentation