59 lines
1.8 KiB
Java
59 lines
1.8 KiB
Java
package games.dmg.spigotquestboard;
|
|
|
|
import java.time.Instant;
|
|
import java.util.List;
|
|
import java.util.Objects;
|
|
import java.util.UUID;
|
|
|
|
record Quest(
|
|
UUID id,
|
|
UUID issuerId,
|
|
String issuerName,
|
|
String requestedMaterial,
|
|
int requestedAmount,
|
|
List<EscrowItem> reward,
|
|
Instant createdAt,
|
|
Instant expiresAt,
|
|
QuestStatus status
|
|
) {
|
|
Quest {
|
|
Objects.requireNonNull(id, "id");
|
|
Objects.requireNonNull(issuerId, "issuerId");
|
|
if (Objects.requireNonNull(issuerName, "issuerName").isBlank()) {
|
|
throw new IllegalArgumentException("Issuer name must not be blank");
|
|
}
|
|
if (Objects.requireNonNull(requestedMaterial, "requestedMaterial").isBlank()) {
|
|
throw new IllegalArgumentException("Requested material must not be blank");
|
|
}
|
|
if (requestedAmount <= 0) {
|
|
throw new IllegalArgumentException("Requested amount must be positive");
|
|
}
|
|
reward = List.copyOf(Objects.requireNonNull(reward, "reward"));
|
|
if (reward.isEmpty()) {
|
|
throw new IllegalArgumentException("Reward must not be empty");
|
|
}
|
|
Objects.requireNonNull(createdAt, "createdAt");
|
|
Objects.requireNonNull(expiresAt, "expiresAt");
|
|
Objects.requireNonNull(status, "status");
|
|
if (!expiresAt.isAfter(createdAt)) {
|
|
throw new IllegalArgumentException("Expiration must follow creation");
|
|
}
|
|
}
|
|
|
|
Quest(
|
|
UUID id,
|
|
UUID issuerId,
|
|
String issuerName,
|
|
String requestedMaterial,
|
|
int requestedAmount,
|
|
List<EscrowItem> reward,
|
|
Instant createdAt,
|
|
Instant expiresAt
|
|
) {
|
|
this(
|
|
id, issuerId, issuerName, requestedMaterial, requestedAmount, reward,
|
|
createdAt, expiresAt, QuestStatus.ACTIVE
|
|
);
|
|
}
|
|
}
|