package io.github.vyo.hellojersey.rest;

import io.github.vyo.hellojersey.entity.EMF;
import io.github.vyo.hellojersey.entity.Greeting;
import io.github.vyo.hellojersey.repository.GreetingRepository;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;

import javax.annotation.PostConstruct;
import javax.inject.Singleton;
import javax.ws.rs.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;

/**
 * Created by Manuel Weidmann on 01.03.2015.
 */
@Singleton
@Api(value = "hellojersey", description = "'Hello World'-style endpoint")
@Path("rest/hellojersey")
public class HelloJersey {

    @Context
    EMF emf;

    @Context
    GreetingRepository greetingRepository;

    public HelloJersey() {
    }

    @PostConstruct
    private void info() {
        //reminder: @Context injected resources are available AFTER construction, not during it
        //reference here if needed
    }

    @GET
    @Path("hello")
    @Produces(MediaType.APPLICATION_JSON)
    @ApiOperation(value = "Returns a simple greeting", notes = "Requires no parameter.", response =
            Greeting.class)
    @ApiResponses({@ApiResponse(code = 200, message = "Jersey is alive and well!")})
    public Greeting getGreeting() {
        return greetingRepository.defaultGreeting();
    }

    @GET
    @Path("echo/{echo}")
    @Produces(MediaType.APPLICATION_JSON)
    @ApiOperation(value = "Greets you with an echo of your message", notes = "Requires an alias to be " +
            "specified as path parameter, outputs a Greeting object in JSON representation.", response = Greeting.class)
    @ApiResponses({@ApiResponse(code = 200, message = "Enjoy your echo!")})
    public Greeting getEcho(@PathParam("echo") String echo) {
        return new Greeting(new StringBuilder(echo).reverse().toString());
    }

    @GET
    @Path("hello/store/{alias}")
    @Produces(MediaType.APPLICATION_JSON)
    @ApiOperation(value = "Returns a simple greeting stored on the server", notes = "Requires an alias to be " +
            "specified as path parameter.", response = Greeting.class)
    @ApiResponses({@ApiResponse(code = 200, message = "Stored Greeting retrieved."), @ApiResponse(code = 404, message
            = "No Greeting found for requested alias.")})
    public Greeting retrieveGreeting(@PathParam("alias") String alias) {
        return greetingRepository.findGreeting(alias);
    }

    @POST
    @Path("hello/store/{alias}")
    @Consumes(MediaType.APPLICATION_JSON)
    @ApiOperation(value = "Stores a simple greeting on the server", notes = "Requires an alias to be specified as " +
            "path parameter, and a Greeting object to be posted")
    @ApiResponses({@ApiResponse(code = 204, message = "Message stored")})
    public void storeGreeting(@PathParam("alias") String alias, Greeting greeting) {
        greetingRepository.storeGreeting(alias, greeting);
    }

}
@@ -268,24 +268,64 @@
 iOperation;%0A
+import io.swagger.annotations.ApiParam;%0A
 import io.sw
@@ -1333,16 +1333,43 @@
 d well!%22
+, response = Greeting.class
 )%7D)%0A    
@@ -1835,16 +1835,41 @@
 r echo!%22
+, response = String.class
 )%7D)%0A    
@@ -1892,16 +1892,83 @@
 getEcho(
+@ApiParam(value = %22Your greeting message%22, defaultValue = %22hello%22) 
 @PathPar
@@ -2425,16 +2425,43 @@
 rieved.%22
+, response = Greeting.class
 ), @ApiR
@@ -2575,32 +2575,113 @@
 etrieveGreeting(
+@ApiParam(value = %22The alias of the requested greeting%22, defaultValue = %22hello%22) 
 @PathParam(%22alia
@@ -3140,40 +3140,269 @@
 ng(@
-PathParam(%22alias%22) String alias,
+ApiParam(value = %22The alias under which to store the greeting%22, defaultValue = %22hello%22) @PathParam(%22alias%22) String alias,%0A         @ApiParam(value = %22The actual greeting to store%22, required = true, defaultValue = %22%7Balias: %5C%22hello%5C%22 , message:%5C%22hello there!%5C%22%7D%22)
  Gre
@@ -3486,8 +3486,9 @@
     %7D%0A%0A%7D
+%0A

Add example values to swagger spec