package market.guess.ui.console.command; import market.guess.api.CatalogContext; import market.guess.ui.console.io.InputProcessor; public final class LoadFileMenuCommand implements MenuCommand { private final CatalogContext catalog; private final InputProcessor io; public LoadFileMenuCommand(CatalogContext catalog, InputProcessor io) { this.catalog = catalog; this.io = io; } @Override public int getIndex() { return 1; } @Override public String getName() { return "Load events from file"; } @Override public void execute() { var path = io.readPath("Please enter the full file path to the XML file: "); var result = catalog.loadEvents(path); if (result.isSuccess()) { io.println( "Successfully loaded %d event(s) from %s." .formatted(result.getData().eventsLoaded(), result.getData().source())); return; } var errorMsg = result.getDetails() != null && !result.getDetails().isBlank() ? result.getDetails() : result.getMessage(); io.println("The file was not loaded: %s".formatted(errorMsg)); } }