package xyz.nulldev.ts.api.http;

import spark.Spark;
import xyz.nulldev.ts.DIReplacement;
import xyz.nulldev.ts.api.http.debug.DebugLibrary;
import xyz.nulldev.ts.api.http.image.CoverRoute;
import xyz.nulldev.ts.api.http.image.ImageRoute;
import xyz.nulldev.ts.api.http.library.CreateBackupRoute;
import xyz.nulldev.ts.api.http.library.LibraryRoute;
import xyz.nulldev.ts.api.http.library.RestoreFromFileRoute;
import xyz.nulldev.ts.api.http.manga.*;

/**
 * Project: TachiServer
 * Author: nulldev
 * Creation Date: 12/07/16
 */
public class HttpAPI {
    public static final String API_ROOT = "/api";

    private ImageRoute imageRoute = new ImageRoute(DIReplacement.get().getLibrary());
    private CoverRoute coverRoute = new CoverRoute(DIReplacement.get().getLibrary());
    private LibraryRoute libraryRoute = new LibraryRoute(DIReplacement.get().getLibrary());
    private MangaRoute mangaRoute = new MangaRoute(DIReplacement.get().getLibrary());
    private ChaptersRoute chapterRoute = new ChaptersRoute(DIReplacement.get().getLibrary());
    private PageCountRoute pageCountRoute = new PageCountRoute(DIReplacement.get().getLibrary());
    private CreateBackupRoute createBackupRoute = new CreateBackupRoute(DIReplacement.get().getLibrary());
    private RestoreFromFileRoute restoreFromFileRoute = new RestoreFromFileRoute(DIReplacement.get().getLibrary());
    private FaveRoute faveRoute = new FaveRoute(DIReplacement.get().getLibrary());
    private ReadingStatusRoute readingStatusRoute = new ReadingStatusRoute(DIReplacement.get().getLibrary());
    private UpdateRoute updateRoute = new UpdateRoute(DIReplacement.get().getLibrary());

    public void start() {
        Spark.staticFiles.header("Access-Control-Allow-Origin", "*");
        Spark.staticFiles.location("/static");
        Spark.get(API_ROOT + "/img/:mangaId/:chapterId/:page", imageRoute);
        Spark.get(API_ROOT + "/img/:mangaId/:chapterId/:page/", imageRoute);
        Spark.get(API_ROOT + "/cover/:mangaId", coverRoute);
        Spark.get(API_ROOT + "/cover/:mangaId/", coverRoute);
        Spark.get(API_ROOT + "/library", libraryRoute);
        Spark.get(API_ROOT + "/library/", libraryRoute);
        Spark.get(API_ROOT + "/manga_info/:mangaId", mangaRoute);
        Spark.get(API_ROOT + "/manga_info/:mangaId/", mangaRoute);
        Spark.get(API_ROOT + "/chapters/:mangaId", chapterRoute);
        Spark.get(API_ROOT + "/chapters/:mangaId/", chapterRoute);
        Spark.get(API_ROOT + "/page_count/:mangaId/:chapterId", pageCountRoute);
        Spark.get(API_ROOT + "/page_count/:mangaId/:chapterId/", pageCountRoute);
        Spark.get(API_ROOT + "/backup", createBackupRoute);
        Spark.get(API_ROOT + "/backup/", createBackupRoute);
        Spark.post(API_ROOT + "/restore_file", restoreFromFileRoute);
        Spark.post(API_ROOT + "/restore_file/", restoreFromFileRoute);
        Spark.get(API_ROOT + "/fave/:mangaId", faveRoute);
        Spark.get(API_ROOT + "/fave/:mangaId/", faveRoute);
        Spark.get(API_ROOT + "/reading_status/:mangaId/:chapterId", readingStatusRoute);
        Spark.get(API_ROOT + "/reading_status/:mangaId/:chapterId/", readingStatusRoute);
        Spark.get(API_ROOT + "/update/:mangaId/:updateType", updateRoute);
        Spark.get(API_ROOT + "/update/:mangaId/:updateType/", updateRoute);
        Spark.get("/", new DebugLibrary(DIReplacement.get().getLibrary()));
    }
}

@@ -1785,24 +1785,62 @@
 %22/static%22);%0A
+        //Get an image from a chapter%0A
         Spar
@@ -1895,32 +1895,32 @@
 %22, imageRoute);%0A
-
         Spark.ge
@@ -1972,32 +1972,67 @@
 %22, imageRoute);%0A
+        //Get the cover of a manga%0A
         Spark.ge
@@ -2130,32 +2130,58 @@
 %22, coverRoute);%0A
+        //Get the library%0A
         Spark.ge
@@ -2269,32 +2269,68 @@
  libraryRoute);%0A
+        //Get details about a manga%0A
         Spark.ge
@@ -2438,32 +2438,70 @@
 %22, mangaRoute);%0A
+        //Get the chapters of a manga%0A
         Spark.ge
@@ -2609,32 +2609,74 @@
  chapterRoute);%0A
+        //Get the page count of a chapter%0A
         Spark.ge
@@ -2814,32 +2814,61 @@
 ageCountRoute);%0A
+        //Backup the library%0A
         Spark.ge
@@ -2964,32 +2964,62 @@
 teBackupRoute);%0A
+        //Restore the library%0A
         Spark.po
@@ -3135,32 +3135,70 @@
 FromFileRoute);%0A
+        //Favorite/unfavorite a manga%0A
         Spark.ge
@@ -3292,32 +3292,78 @@
 /%22, faveRoute);%0A
+        //Set the reading status of a chapter%0A
         Spark.ge
@@ -3427,32 +3427,32 @@
 ngStatusRoute);%0A
-
         Spark.ge
@@ -3517,32 +3517,65 @@
 ngStatusRoute);%0A
+        //Update a manga/chapter%0A
         Spark.ge

Add more comments in HttpAPI.