package gq.baijie.onetab.api;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import javax.annotation.Nonnull;

public class WebArchive {

  private List<Section> sections;

  @Nonnull
  public static WebArchiveBuilder builder() {
    return new WebArchiveBuilder();
  }

  public WebArchive(List<Section> sections) {
    this.sections = sections;
  }

  public static class Section {
    private List<Item> items;

    public Section(List<Item> items) {
      this.items = items;
    }
  }

  public static class Item {
    private String link;
    private String title;

    public Item(String link, String title) {
      this.link = link;
      this.title = title;
    }
  }

  public static class WebArchiveBuilder {
    final List<SectionBuilder> sectionBuilders = new LinkedList<>();

    public SectionBuilder section() {
      final SectionBuilder newSection = new SectionBuilder();
      sectionBuilders.add(newSection);
      return newSection;
    }

    public WebArchive build() {
      final List<Section> sections = new ArrayList<>(sectionBuilders.size());
      sectionBuilders.forEach(s->sections.add(s.build()));
      return new WebArchive(sections);
    }
  }

  public static class SectionBuilder {
    final List<ItemBuilder> itemBuilders = new LinkedList<>();

    public ItemBuilder item() {
      final ItemBuilder newItem = new ItemBuilder();
      itemBuilders.add(newItem);
      return newItem;
    }

    public Section build() {
      final List<Item> items = new ArrayList<>(itemBuilders.size());
      itemBuilders.forEach(i -> items.add(i.build()));
      return new Section(items);
    }

  }

  public static class ItemBuilder {
    private String link;
    private String title;

    public ItemBuilder setLink(String link) {
      this.link = link;
      return this;
    }

    public ItemBuilder setTitle(String title) {
      this.title = title;
      return this;
    }

    public Item build() {
      return new Item(link, title);
    }
  }

}

@@ -376,24 +376,89 @@
 tions;%0A  %7D%0A%0A
+  public List%3CSection%3E getSections() %7B%0A    return sections;%0A  %7D%0A%0A
   public sta
@@ -477,16 +477,16 @@
 ction %7B%0A
-
     priv
@@ -571,32 +571,95 @@
  = items;%0A    %7D%0A
+%0A    public List%3CItem%3E getItems() %7B%0A      return items;%0A    %7D%0A%0A
   %7D%0A%0A  public st
@@ -823,22 +823,137 @@
  title;%0A
-
     %7D%0A
+%0A    public String getLink() %7B%0A      return link;%0A    %7D%0A%0A    public String getTitle() %7B%0A      return title;%0A    %7D%0A%0A
   %7D%0A%0A  p

add getters of WebArchive