package hu.ppke.itk.java.zh1.feladat1;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.List;

public class Main {

	private Catalog catalog;

	public Main() {
		Reader reader = new Reader();
		List<Album> albums = reader.readDatabase();
		catalog = new Catalog(albums);
	}

	private void run() {
		String chosen = null;

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		printHelp();

		while (!"0".equals(chosen)) {
			try {
				chosen = br.readLine();

				switch (chosen) {
				case "0": {
					continue;
				}
				case "1": {
					System.out.print("Give me the number: ");
					String line = br.readLine();
					int rating = Integer.parseInt(line);
					System.out.println(catalog.getAlbumsRatedAtleast(rating));
					break;
				}
				case "2": {
					System.out.print("Give me the band: ");
					String band = br.readLine();
					System.out.println(catalog.getAlbumsOfBand(band));
					break;
				}
				case "3": {
					System.out.print("Give me the band: ");
					String band = br.readLine();

					System.out.print("Give me the title: ");
					String title = br.readLine();

					System.out.println(catalog.getAlbumsWithBandAndTitle(band, title));
					break;
				}
				case "4": {
					catalog.writeToFile();
					break;
				}
				default: {
					printHelp();
				}
				}
				
				System.out.println("\nGive the function: ");
			} catch (Exception e) {
				printHelp();
			}
		}
	}

	private void printHelp() {
		System.out.println("\nMENU");
		System.out.println("1, Best albums");
		System.out.println("2, Albums of band");
		System.out.println("3, Albums with title and band");
		System.out.println("4, Write sorted albums");
		System.out.println("0, Exit");
	}

	public static void main(String[] args) {
		new Main().run();
	}
}
