package moe.ymc.acron.config.json; import com.google.gson.annotations.SerializedName; import moe.ymc.acron.auth.Action; import org.jetbrains.annotations.NotNull; import java.util.List; class Client implements ConfigJsonObject { @SerializedName("id") private final String id; @SerializedName("token") private final String token; @SerializedName("policy_mode") private final Action policyMode; @SerializedName("rules") private final List rules; private Client(String id, String token, Action policyMode, List rules) { this.id = id; this.token = token; this.policyMode = policyMode; this.rules = rules; } @Override public @NotNull moe.ymc.acron.auth.Client create(boolean startup) throws ConfigDeserializationException { if (id == null || id.trim().equals("") || token == null || token.trim().equals("")) { throw new ConfigDeserializationException(".clients[].id or .clients[].token is not supplied."); } return new moe.ymc.acron.auth.Client(id, token, policyMode == null ? Action.DENY : policyMode, rules == null ? new moe.ymc.acron.auth.Rule[]{} : rules.stream().map(rule -> rule.create(startup)).toList() .toArray(new moe.ymc.acron.auth.Rule[rules.size()])); } }