/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package referencelibrary;

import java.util.HashMap;

/**
 *
 * @author juhapekm
 */
public class UI {
    private IO io;
    
    public void run() {
        io = new ConsoleIO();
        io.print("Reference library");
        printAvailableCommands();
        String command = "q";
        command = io.readLine("\nChoose command: \n");
        while(!command.equals("q")) {
            //call chosen functionality
            switch (command){
                case "a":   addNewReference();
                            break;
                case "g":   generateBixTexFile();
                            break;
            }
            //new command
            printAvailableCommands();
            command = io.readLine("\nChoose command: \n");
        }
        io.print("Ohjelma loppuu..");
    }
    
    public void printAvailableCommands() {
        io.print("(q)uit," + "\n" + "(a)dd new reference," + "\n" + "(g)enerate bibtex" + "\n");
    }
    
    public void addNewReference() {
        io.print("Add new reference");
        
        //promt reference type
        String command = io.readLine("\nChoose reference type: \n");
        io.print("(B)ook, \n(O)ther\n");
        
        //switch (reference type)
        switch(command){
            case "B":   //Call addBook
                        io.print("--adding not implement");
                        //io.print("Reference added!");
                        break;
            case "O":   io.print("--adding not implement");
                        //io.print("Reference added!");
                        break;
        } 
    }
    
    public void addNewBook() {
        String referenceType = "Book";
        String referenceName = io.readLine("Reference id");
        String author = io.readLine("Author: ");
        String title = io.readLine("Title: ");
        String year = io.readLine("Year: ");
        String publisher = io.readLine("Publisher: ");
        HashMap<String, String> newRefHash = new HashMap<String, String>();
        newRefHash.put("author", author);
        newRefHash.put("title", title);
        newRefHash.put("year", year);
        newRefHash.put("publisher", publisher);
        //Reference newRef = new Reference();
    }
    
    public void generateBixTexFile() {
        io.print("Generating bibTex -file");
        //call bibtex-file generator
        io.print("--generating not implemented");
        
        io.print("Generating done!");
    }
}

@@ -1237,16 +1237,17 @@
   //prom
+p
 t refere
@@ -1284,32 +1284,45 @@
 d = io.readLine(
+%0A            
 %22%5CnChoose refere
@@ -1337,30 +1337,8 @@
 : %5Cn
-%22);%0A        io.print(%22
 (B)o
@@ -1452,22 +1452,21 @@
 :   
-//Call 
 add
+New
 Book
+();
 %0A   
@@ -1805,24 +1805,56 @@
 NewBook() %7B%0A
+        //prompt reference name%0A
         Stri
@@ -1936,24 +1936,129 @@
 rence id%22);%0A
+        Reference newRef = new Reference(referenceType, referenceName);%0A        %0A        //prompt fields%0A
         Stri
@@ -2253,75 +2253,29 @@
     
-HashMap%3CString, String%3E newRefHash = new HashMap%3CString, String%3E();
+%0A        //set fields
 %0A   
@@ -2285,24 +2285,25 @@
   newRef
-Hash.put
+.setField
 (%22author
@@ -2328,24 +2328,25 @@
   newRef
-Hash.put
+.setField
 (%22title%22
@@ -2369,24 +2369,25 @@
   newRef
-Hash.put
+.setField
 (%22year%22,
@@ -2412,16 +2412,17 @@
 wRef
-Hash.put
+.setField
 (%22pu
@@ -2439,24 +2439,33 @@
 publisher);%0A
+        %0A
         //Re
@@ -2462,25 +2462,30 @@
       //
-R
+save r
 eference
  newRef 
@@ -2480,34 +2480,87 @@
 ence
- newRef = new Reference();
+%0A        //App.save(newRef) TAI%0A        //BibtexConverter.save(newRef)%0A        
 %0A   

modify 'add book' function