
// Gutenberg.java 

/* DTO (Data Transfer Object) classes used by 
   Google GSON to map the JSON responses from the
   Gutendex API (https://gutendex.com/) to Java  objects.

   Based on code generated by
   https://json2csharp.com/code-converters/json-to-pojo
   when supplied with JSON output for a search for
   "Dickens Great" and others carried out at
   https://gutendex.com/
*/


import java.util.*;

import com.google.gson.annotations.*;



class Gutenberg
{
  int count;
  Object next;
  Object previous;

  @SerializedName("results")   // use a better name
  ArrayList<Book> books;
}


class Book
{
  int id;
  String title;
  ArrayList<Person> authors;
  ArrayList<Person> translators;
  ArrayList<String> subjects;
  ArrayList<String> bookshelves;
  ArrayList<String> languages;
  boolean copyright;
  String media_type;
  Formats formats;
  int download_count;
}


class Person
{
  String name;
  int birth_year;
  int death_year;
}


class Formats
/* links mime-type to a URL;
   the name changes and extra methods were added by ad

   See: https://www.gutenberg.org/help/file_formats.html
*/
{
  @SerializedName("application/x-mobipocket-ebook")
  String mobi;

  @SerializedName("application/epub+zip")
  String epub;

  @SerializedName("text/plain")
  String txt;

  @SerializedName("text/plain; charset=utf-8")
  String txt_8;

  @SerializedName("text/plain; charset=us-ascii")
  String txt_ascii;

  @SerializedName("text/plain; charset=iso-8859-1")
  String txt_88591;

  @SerializedName("text/html")
  String html;

  @SerializedName("text/html; charset=utf-8")
  String html_8;

  @SerializedName("text/html; charset=us-ascii")
  String html_ascii;

  @SerializedName("text/html; charset=iso-8859-1")
  String html_88591;

  @SerializedName("text/xml")
  String xml;

  @SerializedName("application/zip")
  String zip;

  @SerializedName("application/octet-stream")
  String octet;

  @SerializedName("application/prs.tex")
  String tex;

  @SerializedName("application/pdf")
  String pdf;

  @SerializedName("application/rdf+xml")
  String rdf;

  @SerializedName("image/jpeg")
  String jpg;

  @SerializedName("audio/ogg")
  String ogg;

  @SerializedName("audio/mp4")
  String mp4;   // m4b

  @SerializedName("audio/mpeg")
  String mpeg;  // mp3

  @SerializedName("audio/midi")
  String mid;


  // --------------


  private TreeMap<String, String> links = new TreeMap<>();
    // maps media labels to URL strings


  public TreeMap<String, String> getLinks()
  /* collect all the media labels used by this book 
     in the links map
  */
  {
    if (mobi != null)
      links.put("mobi", mobi);
    if (epub != null)
      links.put("epub", epub);

    if (txt != null)
      links.put("txt", txt);
    if (txt_ascii != null)
      links.put("txt_ascii", txt_ascii);
    if (txt_8 != null)
      links.put("txt_8", txt_8);
    if (txt_88591 != null)
      links.put("txt_88591", txt_88591);

    if (xml != null)
      links.put("xml", xml);

    if (html != null)
      links.put("html", html);
    if (html_ascii != null)
      links.put("html_ascii", html_ascii);
    if (html_8 != null)
      links.put("html_8", html_8);
    if (html_88591 != null)
      links.put("html_88591", html_88591);

    if (zip != null)
      links.put("zip", zip);
    if (octet != null)
      links.put("octet", octet);

    if (tex != null)
      links.put("tex", tex);
    if (pdf != null)
      links.put("pdf", pdf);
    if (rdf != null)
      links.put("rdf", rdf);

    if (jpg != null)
      links.put("jpg", jpg);

    if (ogg != null)
      links.put("ogg", ogg);
    if (mp4 != null)
      links.put("mp4", mp4);
    if (mpeg != null)
      links.put("mpeg", mpeg);
    if (mid != null)
      links.put("mid", mid);

    return links;
  }  // end of getLinks()

} // end of Formats class

