// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.restapi;

import com.yahoo.container.jdisc.HttpRequest;
import com.yahoo.container.jdisc.HttpResponse;
import com.yahoo.slime.Cursor;
import com.yahoo.slime.JsonFormat;
import com.yahoo.slime.Slime;

import java.io.IOException;
import java.io.OutputStream;
import java.net.URI;

/**
 * Returns a response containing an array of links to sub-resources
 * 
 * @author bratseth
 */
public class ResourceResponse extends HttpResponse {

    private final Slime slime = new Slime();

    public ResourceResponse(URI parentUrl, String ... subResources) {
        super(200);
        Cursor resourceArray = slime.setObject().setArray("resources");
        for (String subResource : subResources) {
            Cursor resourceEntry = resourceArray.addObject();
            resourceEntry.setString("url", new Uri(parentUrl).append(subResource)
                                                             .withTrailingSlash()
                                                             .toString());
        }
    }

    public ResourceResponse(HttpRequest request, String ... subResources) {
        this(request.getUri(), subResources);
    }

    @Override
    public void render(OutputStream stream) throws IOException {
        new JsonFormat(true).encode(stream, slime);
    }

    @Override
    public String getContentType() { return "application/json"; }

}

@@ -12,25 +12,19 @@
 t 20
-17 Yahoo Holdings
+20 Oath Inc
 . Li
@@ -201,211 +201,64 @@
 hoo.
-container.jdisc.HttpResponse;%0Aimport com.yahoo.slime.Cursor;%0Aimport com.yahoo.slime.JsonFormat;%0Aimport com.yahoo.slime.Slime;%0A%0Aimport java.io.IOException;%0Aimport java.io.OutputStream;%0Aimport java.net.URI
+slime.Slime;%0A%0Aimport java.net.URI;%0Aimport java.util.List
 ;%0A%0A/
@@ -394,20 +394,25 @@
 extends 
-Http
+SlimeJson
 Response
@@ -424,47 +424,134 @@
    p
-rivate final Slime slime = new Slime();
+ublic ResourceResponse(URI parentUrl, List%3CString%3E subResources) %7B%0A        super(200, toSlime(parentUrl, subResources));%0A    %7D
 %0A%0A  
@@ -630,33 +630,304 @@
     
-super(200
+this(parentUrl, List.of(subResources)
 );%0A    
+%7D%0A%0A
     
-Curso
+public ResourceResponse(HttpRequest request, String ... subResources) %7B%0A        this(request.getUri(), subResources);%0A    %7D%0A%0A    private static Slime toSlime(URI parentUrl, List%3CString%3E subResources) %7B%0A        var slime = new Slime();%0A        va
 r re
@@ -994,22 +994,19 @@
    for (
-String
+var
  subReso
@@ -1044,13 +1044,10 @@
     
-Curso
+va
 r re
@@ -1344,355 +1344,29 @@
     
-%7D%0A%0A
     
-public ResourceResponse(HttpRequest request, String ... subResources) %7B%0A        this(request.getUri(), subResources);%0A    %7D%0A%0A    @Override%0A    public void render(OutputStream stream) throws IOException %7B%0A        new JsonFormat(true).encode(stream, slime);%0A    %7D%0A%0A    @Override%0A    public String getContentType() %7B return %22application/json%22;
+return slime;%0A   
  %7D%0A%0A

Simplify ResourceResponse