package kiyut.alkitab.options;

import java.util.prefs.Preferences;

/**
 *
 * 
 */
public final class BookViewerOptions extends AbstractOptions {
    private static BookViewerOptions instance; // The single instance
    static {
        instance = new BookViewerOptions();
    }
    
    /**
     * Returns the single instance
     *
     * @return The single instance.
     */
    public static BookViewerOptions getInstance() {
        return instance;
    }
    
    private static final String PARALLEL_BOOK_LIMIT = "parallel-book-limit";
    private static final String SEARCH_LIMIT = "search-limit";
    private static final String VERSES_PER_TAB = "verses-per-tab";
    private static final String DEFAULT_BIBLE = "default-bible";
    private static final String DEFAULT_DICTIONARY = "default-dictionary";
    private static final String DEFAULT_DAILY_DEVOTIONS = "default-daily-devotions";
    private static final String BOOK_PATH = "book-path";
    private static final String DOWNLOAD_PATH = "download-path";
    
    private int parallelBookLimit;
    private int searchLimit;
    private int versesPerTab;
    private String defaultBible;
    private String defaultDictionary;
    private String defaultDailyDevotions;
    
    protected BookViewerOptions() {
        nodeName = "bookviewer";
        load();
    }
    
    public void load() {
        Preferences prefs = getPreferences();

        parallelBookLimit = prefs.getInt(PARALLEL_BOOK_LIMIT, 5);
        searchLimit = prefs.getInt(SEARCH_LIMIT, 50);
        versesPerTab = prefs.getInt(VERSES_PER_TAB, 50);
        defaultBible = prefs.get(DEFAULT_BIBLE, null);
        defaultDictionary = prefs.get(DEFAULT_DICTIONARY, null);
        defaultDailyDevotions = prefs.get(DEFAULT_DAILY_DEVOTIONS, null);
    }
    
    public void save() {
        Preferences prefs = getPreferences();
        prefs.putInt(PARALLEL_BOOK_LIMIT, parallelBookLimit);
        prefs.putInt(SEARCH_LIMIT, searchLimit);
        prefs.putInt(VERSES_PER_TAB, versesPerTab);
        
        if (defaultBible != null) {
            prefs.put(DEFAULT_BIBLE, defaultBible);
        } else {
            prefs.remove(DEFAULT_BIBLE);
        }
        if (defaultDictionary != null) {
            prefs.put(DEFAULT_DICTIONARY, defaultDictionary);
        } else {
            prefs.remove(DEFAULT_DICTIONARY);
        }
        if (defaultDailyDevotions != null) {
            prefs.put(DEFAULT_DAILY_DEVOTIONS, defaultDailyDevotions);
        } else {
            prefs.remove(DEFAULT_DAILY_DEVOTIONS);
        }
    }
 
    public void setParallelBookLimit(int limit) {
        this.parallelBookLimit = limit;
    }
    
    public int getParallelBookLimit() {
        return this.parallelBookLimit;
    }
    
    public void setSearchLimit(int limit) {
        this.searchLimit = limit;
    }
    
    public int getSearchLimit() {
        return this.searchLimit;
    }
    
    public void setVersesPerTab(int versesCount) {
        this.versesPerTab = versesCount;
    }
    
    public int getVersesPerTab() {
        return this.versesPerTab;
    }
    
    public void setDefaultBible(String initials) {
        this.defaultBible = initials;
    }
    
    public String getDefaultBible() {
        return this.defaultBible;
    }
    
    public void setDefaultDictionary(String initials) {
        this.defaultDictionary = initials;
    }
    
    public String getDefaultDictionary() {
        return this.defaultDictionary;
    }
    
    public void setDefaultDailyDevotions(String initials) {
        this.defaultDailyDevotions = initials;
    }
    
    public String getDefaultDailyDevotions() {
        return this.defaultDailyDevotions;
    }
}
