package TodoListApp.Domain;

import java.util.ArrayList;
import TodoListApp.Domain.*;

public class TaskList {

	private ArrayList<Task> alleTasks;

	public TaskList() {

		this.alleTasks = new ArrayList<>();
	}

	public boolean addTaskZuList(String title, String beschreibung, String eingabeTaskprioritaet) {
		Task t = AddTask.addTaskZuList(title, beschreibung, eingabeTaskprioritaet);
		if (t == null)
			return false;
		
		alleTasks.add(t);
		return true;
	}

	public boolean removeTask(String title) {
		Task t = findTask(title);
		if (t == null)
			return false;
		
		alleTasks.remove(t);
		return true;
	}

	public boolean markTaskAsDone(String title) {
		Task t = findTask(title);
		if (t == null)
			return false;
		t.setIstGemacht(true);
		return t.isIstGemacht();
	}
	
	

	public ArrayList<String> printAlleGemachteTasks() {
		ArrayList<String> alleGemachteTasks = new ArrayList<>();
		for (Task t : alleTasks) {
			if (t.isIstGemacht() == true)
				alleGemachteTasks.add(t.toString());
		}
		return alleGemachteTasks;
	}

	public ArrayList<String> printAllTask() {
		ArrayList<String> printallTasks = new ArrayList<>();
		int index = 1;
		for (Task t : alleTasks) {
			printallTasks.add(index++ + ".Task: " + t.toString() + ".");
		}
		return printallTasks;
	}

	private Task findTask(String title) {
		for (Task t : alleTasks) 
			if (t.getTitle().equalsIgnoreCase(title))
				return t;
		return null;
	}

}
