package Übungen.MyChat_App;

import java.util.ArrayList;
import java.util.Scanner;


public class ChatRom {
	
	private ArrayList<String> saveMessagesBetweenUsers;

	ChatRom() {
		this.saveMessagesBetweenUsers = new ArrayList<>();
	}

	public void sendeNachricht(User sender, User empfaenger, String message) {
		String foramttedNachricht = sender.getName() + " an " + empfaenger.getName() + ": " + message;
		saveMessagesBetweenUsers.add(foramttedNachricht);
		empfaenger.setMessage(message);
	}

	public void zeigeChatHistorie() {
		for (String s : saveMessagesBetweenUsers)
			System.out.println(s);
	}

	public static void main(String[] args) {
		User obai = new User("Obai");
		User omar = new User("Omar");
		
		ChatRom chatRoom = new ChatRom();
		
		Scanner textEingabe = new Scanner(System.in);
		String message;
		while (true) {
			System.out.print("> ");
			message = textEingabe.nextLine();
			chatRoom.sendeNachricht(obai, omar, message);
			chatRoom.zeigeChatHistorie();

			System.out.print("> ");
			message = textEingabe.nextLine();
			chatRoom.sendeNachricht(omar, obai, message);

			chatRoom.zeigeChatHistorie();

		}

	}
}
