import java.util.ArrayList;
import java.util.List;

public class Chapter11Design {
    static final class History {
        private final List<String> lines = new ArrayList<>();

        void recordInteraction(String input, String response) {
            if (input == null || input.isBlank()) {
                throw new IllegalArgumentException("Input is required.");
            }
            lines.add("USER: " + input.strip());
            lines.add("BOT: " + response);
        }

        List<String> entries() {
            return List.copyOf(lines);
        }
    }

    static final class CommandProcessor {
        String respond(String command) {
            return switch (command) {
                case "hi" -> "Hello!";
                case "help" -> "Commands: hi, help, and tip.";
                case "tip" -> "Prefer composition for has-a relationships.";
                default -> "I didn't understand.";
            };
        }
    }

    public static void main(String[] args) {
        History history = new History();
        CommandProcessor processor = new CommandProcessor();
        String response = processor.respond("tip");
        history.recordInteraction("tip", response);
        System.out.println(history.entries());
    }
}
