blob: 642ad782b8ecedc6d692fc1835d1b819a458bf6f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
package market.guess.ui.console.command;
import market.guess.api.CatalogContext;
import market.guess.model.event.CommissionTiming;
import market.guess.model.event.EventStatus;
import market.guess.ui.console.io.InputProcessor;
public final class EventDetailsMenuCommand implements MenuCommand {
private final CatalogContext catalog;
private final InputProcessor io;
public EventDetailsMenuCommand(CatalogContext catalog, InputProcessor io) {
super();
this.catalog = catalog;
this.io = io;
}
@Override
public int getIndex() {
return 3;
}
@Override
public String getName() {
return "Show event details";
}
@Override
public void execute() {
var result = catalog.getAllEvents();
if (!result.isSuccess()) {
io.println("Failed to list events: %s.".formatted(result.getMessage()));
return;
}
var events = result.getData();
var viewable = events.stream().filter(event -> event.status() != EventStatus.DRAFT).toList();
if (viewable.isEmpty()) {
io.println("No events are currently loaded. Please load a valid XML file first.");
return;
}
io.newLine();
io.println("Available events:");
var pick =
io.readSelect(
"Pick an event: ",
viewable,
event -> "[ID: %d] %s (%s)".formatted(event.displayId(), event.name(), event.status()));
var result2 = catalog.getEvent(pick.key());
var event = result2.getData();
if (event == null) {
io.println("That event is no longer available.");
return;
}
io.newLine();
io.println("=== Event Details ===");
io.println("Event ID: %d".formatted(event.summary().displayId()));
io.println("Name: %s".formatted(event.summary().name()));
io.println("Description: %s".formatted(event.summary().description()));
io.println(
"Commission: %d%% (%s)"
.formatted(
event.summary().commissionPercent(),
event.summary().commissionTiming() == CommissionTiming.ON_CLOSE
? "on-close"
: "on-purchase"));
io.println("Status: %s".formatted(event.summary().status()));
io.printState(event.state());
io.printHistory(event.history());
if (event.settledMarket() != null && !event.settledMarket().isBlank()) {
io.newLine();
io.println("Winning option: %s".formatted(event.settledMarket()));
}
}
}
|