package org.wikipedia.readinglist.page.database;

import android.support.annotation.NonNull;
import android.util.Base64;

import org.wikipedia.page.PageTitle;
import org.wikipedia.readinglist.ReadingList;
import org.wikipedia.readinglist.page.ReadingListPage;
import org.wikipedia.readinglist.page.database.disk.DiskStatus;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public final class ReadingListDaoProxy {

    public static List<PageTitle> pageTitles(@NonNull Collection<ReadingListPage> pages) {
        List<PageTitle> titles = new ArrayList<>();
        for (ReadingListPage page : pages) {
            titles.add(pageTitle(page));
        }
        return titles;
    }

    @NonNull public static PageTitle pageTitle(@NonNull ReadingListPage page) {
        return new PageTitle(page.title(), page.wikiSite(), page.thumbnailUrl(), page.description());
    }

    @NonNull public static ReadingListPage page(@NonNull ReadingList list, @NonNull PageTitle title) {
        long now = System.currentTimeMillis();
        return ReadingListPage
                .builder()
                .diskStatus(DiskStatus.OUTDATED)
                .key(key(title))
                .listKeys(listKey(list))
                .site(title.getWikiSite())
                .namespace(title.namespace())
                .title(title.getDisplayText())
                .diskPageRevision(title.hasProperties() ? title.getProperties().getRevisionId() : 0)
                .mtime(now)
                .atime(now)
                .thumbnailUrl(title.hasProperties() ? title.getProperties().getLeadImageUrl() : null)
                .description(title.getDescription())
                .build();
    }

    @NonNull public static String key(@NonNull PageTitle title) {
        // TODO: this should use the following but PageTitles often do not have Properties and page
        //       ID is not preserved elsewhere.
        // return "wikipedia-" + title.getWikiSite().languageCode() + '-' + title.getProperties().getPageId();
        return Base64.encodeToString((title.getWikiSite().languageCode() + '-' + title.getDisplayText()).getBytes(),
                Base64.NO_WRAP);
    }

    @NonNull public static String listKey(@NonNull ReadingList list) {
        // TODO: we need to rekey all pages if a user changes the list title.
        return listKey(list.getTitle());
    }

    @NonNull public static String listKey(@NonNull String title) {
        // TODO: we need to rekey all pages if a user changes the list title.
        return Base64.encodeToString(title.getBytes(), Base64.NO_WRAP);
    }

    private ReadingListDaoProxy() { }
}

@@ -322,398 +322,48 @@
 s;%0A%0A
-import java.util.ArrayList;%0Aimport java.util.Collection;%0Aimport java.util.List;%0A%0Apublic final class ReadingListDaoProxy %7B%0A%0A    public static List%3CPageTitle%3E pageTitles(@NonNull Collection%3CReadingListPage%3E pages) %7B%0A        List%3CPageTitle%3E titles = new ArrayList%3C%3E();%0A        for (ReadingListPage page : pages) %7B%0A            titles.add(pageTitle(page));%0A        %7D%0A        return titles;%0A    %7D
+public final class ReadingListDaoProxy %7B
 %0A%0A  

remove unused ReadingListDaoProxy.pageTitles() method