import javax.swing.*;
public class Library
{
	Book[] books = new Book[3];
	Patron[] patrons = new Patron[3];
	Author[] authors;

	public static void main (String[] args)
	{
		Library lib = new Library();
		lib.addBookAuthor();
		lib.showBookAuthor();
		lib.addPatron();
		lib.showPatron();
		//lib.showBookAuthor();
		//lib.patrons[0].checkBookIn();
		//lib.patrons[2].checkBookIn();
		//lib.showPatron();
		//lib.showBookAuthor();
		System.exit(0);
	}

	private void addBookAuthor()
	{
		authors = new Author[1];
		authors[0] = new Author ("Harper Lee", "5/23/54");
		books[0] = new Book (101, "To kill a Mockingbird", authors , 2);

		authors = new Author[2];			// 2 authors in this book
		authors[0] = new Author ("Amy Tan", "1/03/14");
		authors[1] = new Author ("Jack London", "1/12/06");
		books[1] = new Book (102, "The Joy Luck Club", authors, 1);

		authors = new Author[1];
		authors[0] = new Author ("C.S.Lewis", "2/03/74");
		books[2] = new Book (103, "Perelandra", authors, 2);
	}

	private void addPatron()
	{
		patrons[0] = new Patron(1, "Fred Capestany", 0, books[2]);
		patrons[1] = new Patron(2, "Gurpreet Kaur", 0, null);
		patrons[2] = new Patron(3, "Vera Doroshenko", 0, books[2]);
	}

	private void showBookAuthor()				//Library Inventory
	{
		String output = "";
		for (int i=0; i<books.length; i++)
		{
			output+=books[i].getBook_id()+", ";
			output+=books[i].getTitle()+", ";

			//------------------------------number of authors in each book

			int numAuthors = books[i].getAuthors().length;

			for (int x=0; x<books[i].getAuthors().length; x++)
			{
				output+=books[i].getAuthors()[x].getAName();

				if(numAuthors >1)		//if more than 1 author in the book
				{
					output+=", ";		//put comma between authors
					numAuthors--;
				}
			}
			output+=", ";
			output+=books[i].getNum_copies()+", ";
			output+=books[i].getCheckStatus();
			output+="\n";
		}

		output+="\n\nThere are " + books.length + " books in inventory.";
		JOptionPane.showMessageDialog(null, output,"Library Inventory",
							JOptionPane.PLAIN_MESSAGE);
	}

	private void showPatron()
	{
		String output = "";
		for (int i=0; i<patrons.length; i++)
		{
			output+=patrons[i].getPID()+", ";
			output+=patrons[i].getPName()+", ";
			if (patrons[i].getBook() == null)
			{
				output+= "no books";
			}
			else
			{
				output+=patrons[i].getBook().getTitle();
			}
			output+="\n";

		}
		output+="\n\nThere are " + patrons.length + " patrons in library.";
		JOptionPane.showMessageDialog(null, output,"Patron Summary",
							JOptionPane.PLAIN_MESSAGE);
	}
}
