import java.util.HashMap;
import java.util.ArrayList;

import spark.ModelAndView;
import spark.template.velocity.VelocityTemplateEngine;
import static spark.Spark.*;

public class App {
    public static void main(String[] args) {
      staticFileLocation("/public");
      String layout = "templates/layout.vtl";

      get("/", (request, response) -> {
        HashMap<String,Object>model = new HashMap<String, Object>();
        model.put("definitions", request.session().attribute("definitions"));
        model.put("template", "templates/index.vtl");
        return new ModelAndView(model, layout);
      }, new VelocityTemplateEngine());

      get("/definitions", (request, response) -> {
        HashMap<String, Object> model = new HashMap<String, Object>();
        model.put("definitions", Definition.all());
        model.put("template", "templates/definitions.vtl");
        return new ModelAndView(model, layout);
        }, new VelocityTemplateEngine());

      get("definitions/new", (request, response) -> {
        HashMap<String, Object> model = new HashMap<String, Object>();
        model.put("template", "templates/definition-form.vtl");
        return new ModelAndView(model, layout);
        }, new VelocityTemplateEngine());

      post("/definitions", (request,response) -> {
        HashMap<String, Object>model = new HashMap<String, Object>();
        Word word = Word.find(Integer.parseInt(request.queryParams("wordId")));
        String description = request.queryParams("description");
        Definition newDefinition = new Definition(description);
        word.addDefinition(newDefinition);
        model.put("word", word);
        model.put("template", "templates/word.vtl");
        return new ModelAndView(model, layout);
      }, new VelocityTemplateEngine());

      get("/definitions/:id", (request, response) -> {
        HashMap<String, Object> model = new HashMap<String, Object>();
        Definition definition = Definition.find(Integer.parseInt(request.params(":id")));
        model.put("definition", definition);
        model.put("template", "templates/definition.vtl");
        return new ModelAndView(model, layout);
      }, new VelocityTemplateEngine());

      get("/words", (request, response) -> {
        HashMap<String, Object> model = new HashMap<String, Object>();
        model.put("words", Word.all());
        model.put("template", "templates/words.vtl");
        return new ModelAndView(model, layout);
      }, new VelocityTemplateEngine());

      get("words/new", (request, response) -> {
        HashMap<String, Object> model = new HashMap<String, Object>();
        model.put("template", "templates/word-form.vtl");
        return new ModelAndView(model, layout);
      }, new VelocityTemplateEngine());

      post("/words", (request,response) -> {
        HashMap<String, Object>model = new HashMap<String, Object>();
        String name = request.queryParams("name");
        Word newWord = new Word(name);
        model.put("word", newWord);
        model.put("template", "templates/success.vtl");
        return new ModelAndView(model, layout);
      }, new VelocityTemplateEngine());

        //RESTful ARCHITECTURE
        //Use POST to create something on the server
        //Use GET to retrieve something from the server
        //Use PUT to change or update something on the server
        //Use DELETE to remove or delete something on the server
        //Keep URLs intuitive
        //Each request from client contains all info necessary for that request

        //ROUTES: Home Page

        // get("/", (request, response) -> {
        //     HashMap<String, Object> model = new HashMap<String, Object>();

        //     model.put("template", "templates/index.vtl");
        //     return new ModelAndView(model, layout);
        // }, new VelocityTemplateEngine());

        //ROUTES: Identification of Resources

        //ROUTES: Changing Resources

    }
}

@@ -3143,32 +3143,747 @@
 lateEngine());%0A%0A
+      get(%22/words/:id%22, (request, response) -%3E %7B%0A        HashMap%3CString, Object%3E model = new HashMap%3CString, Object%3E();%0A        model.put(%22word%22, Word.find(Integer.parseInt(request.params(%22:id%22))));%0A        model.put(%22template%22, %22templates/word.vtl%22);%0A        return new ModelAndView(model, layout);%0A      %7D, new VelocityTemplateEngine());%0A%0A      get(%22/words/:id/definitions/new%22, (request, response) -%3E %7B%0A        HashMap%3CString, Object%3E model = new HashMap%3CString, Object%3E();%0A        model.put(%22word%22, Word.find(Integer.parseInt(request.params(%22:id%22))));%0A        model.put(%22template%22, %22templates/word-definitions-form.vtl%22);%0A        return new ModelAndView(model, layout);%0A      %7D, new VelocityTemplateEngine());%0A%0A
         //RESTfu

add additional get and post method