package industries.doublehelix.furrynotemanager.siteImporters;

import java.io.IOException;
import java.net.MalformedURLException;
import java.sql.SQLException;
import java.util.Calendar;
import java.util.TreeSet;

import industries.doublehelix.furrynotemanager.Note;
import industries.doublehelix.furrynotemanager.User;

public interface Importable {
	/**
	 * Gets all notes since given calendar date (not committed to DB), containing all info that can be gotten
	 * from the note overview (may be different for each site implementing, probably contains all but text)
	 * @param calendar date to use as starting point
	 * @param user the user of which to get the notes
	 * @param importer the worker which is used to call this function, for progress updates (may be null)
	 * @return the imported notes
	 * @throws SQLException 
	 * @throws MalformedURLException 
	 * @throws IOException 
	 */
	public TreeSet<Note> getAllBareboneNotesSince(Calendar calendar, User user, SiteImporter importer) throws MalformedURLException, SQLException, IOException;
	
	/**
	 * get all given notes from the site (not committed to DB)
	 * @param bareboneNotes the barebone (unfinished) notes to get (given parameterlist will be updated)
	 * @param user the user of which to get the notes
	 * @param importer the worker which is used to call this function, for progress updates (may be null)
	 * @return the notes (at the end same as parameter)
	 * @throws IOException 
	 */
	public TreeSet<Note> getNotes(TreeSet<Note> bareboneNotes, User user, SiteImporter importer) throws IOException;
	
	/**
	 * Try to login with the given user's credentials
	 * @param user the user to login
	 * @return true if login was successfull
	 * @throws IOException 
	 * @throws MalformedURLException 
	 */
	public boolean login(User user) throws MalformedURLException, IOException;
	
	/**
	 * Try to log out
	 * @throws IOException 
	 * @throws MalformedURLException 
	 */
	public void logout() throws MalformedURLException, IOException;
	
	/**
	 * checks which user is logged in
	 * @return the name of the user or null if no user is logged in
	 */
	public String getLoggedInUser();
	
	/**
	 * checks if the page is of the "not allowed" variety shown to logged-out users when attempting to access the notes
	 * @param page the page's html to check
	 * @return true if the page is such an error page, false otherwise
	 */
	public boolean isAccessViolationErrorPage(String page);
	
	/**
	 * cancel running methods
	 */
	public void cancel();
}
