package com.sagacloud.endpoints;

import com.github.rjeschke.txtmark.Processor;
import org.apache.commons.io.IOUtils;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import java.io.IOException;
import java.io.StringWriter;

/**
 * Created by wo on 6/12/17.
 */
@Path("doc")
public class Doc {

	@Path("/")
    @GET
    @Produces("text/html;charset=UTF-8")
    public String getDoc() throws IOException {
        String docContentStr = Processor.process(Doc.class.getClassLoader().getResourceAsStream("documentation.md"));
        StringWriter writer = new StringWriter();
        IOUtils.copy(Doc.class.getClassLoader().getResourceAsStream("template.html"), writer, "utf-8");
        String tmplateContentStr = writer.toString();
        return tmplateContentStr.replace("#replaceMePlease#", docContentStr);
    }
    
	@Path("/version")
    @GET
    @Produces("text/html;charset=UTF-8")
    public String getVersion() throws IOException {
        String docContentStr = Processor.process(Doc.class.getClassLoader().getResourceAsStream("version.md"));
        StringWriter writer = new StringWriter();
        IOUtils.copy(Doc.class.getClassLoader().getResourceAsStream("template.html"), writer, "utf-8");
        String tmplateContentStr = writer.toString();
        return tmplateContentStr.replace("#replaceMePlease#", docContentStr);
    }
}
