import java.util.List;

/** Colecciones inmutables, vistas no modificables y copias. */
public class ViewDemo {

    public static void main(String[] args) {
        List<String> fixed = List.of("do", "re", "mi");
        try {
            fixed.add("fa");
        } catch (UnsupportedOperationException e) {
            IO.println("List.of no admite add: " + e.getClass().getSimpleName());
        }

        Playlist playlist = new Playlist();
        playlist.add(new Song("Arena", "Duna", 185));
        List<Song> view = playlist.songs();
        List<Song> copy = List.copyOf(view);
        try {
            view.add(new Song("Arena", "Duna", 185));      // rompería el invariante
        } catch (UnsupportedOperationException e) {
            IO.println("La vista no admite add: " + e.getClass().getSimpleName());
        }

        playlist.add(new Song("Brisa", "Duna", 210));
        IO.println("vista: " + view.size() + " canciones, copia: " + copy.size());
        for (Song s : playlist) {
            IO.println("  " + s.title());
        }
    }
}
