Files
evercatch-java/src/main/java/dev/evercatch/model/CreateDestinationRequest.java
Puranjay Savar Mattas e66227afc4
All checks were successful
PR Management Bot / pr-bot (pull_request) Successful in 7s
PR Title Checker / Validate PR Title Format (pull_request) Successful in 2s
EC-21: FEAT: Added new Java package and initialized the repo
Refers Evercatch/evercatch-board#21
2026-02-19 21:24:58 +00:00

101 lines
2.9 KiB
Java

package dev.evercatch.model;
import com.google.gson.annotations.SerializedName;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Request object for creating a new webhook destination.
*
* <pre>{@code
* CreateDestinationRequest req = CreateDestinationRequest.builder()
* .name("Production")
* .url("https://myapp.com/webhooks")
* .providers(List.of("stripe", "sendgrid"))
* .eventTypes(List.of("payment.*", "email.delivered"))
* .build();
* }</pre>
*/
public class CreateDestinationRequest {
private final String name;
private final String url;
private final List<String> providers;
@SerializedName("event_types")
private final List<String> eventTypes;
private final Map<String, String> headers;
private CreateDestinationRequest(Builder builder) {
this.name = builder.name;
this.url = builder.url;
this.providers = builder.providers;
this.eventTypes = builder.eventTypes;
this.headers = builder.headers;
}
public static Builder builder() {
return new Builder();
}
public String getName() { return name; }
public String getUrl() { return url; }
public List<String> getProviders() { return providers; }
public List<String> getEventTypes() { return eventTypes; }
public Map<String, String> getHeaders() { return headers; }
public static class Builder {
private String name;
private String url;
private List<String> providers;
private List<String> eventTypes;
private Map<String, String> headers = new HashMap<>();
public Builder name(String name) {
this.name = name;
return this;
}
public Builder url(String url) {
this.url = url;
return this;
}
public Builder providers(List<String> providers) {
this.providers = providers;
return this;
}
public Builder eventTypes(List<String> eventTypes) {
this.eventTypes = eventTypes;
return this;
}
public Builder headers(Map<String, String> headers) {
this.headers = headers;
return this;
}
public Builder addHeader(String key, String value) {
this.headers.put(key, value);
return this;
}
public CreateDestinationRequest build() {
if (name == null || name.trim().isEmpty()) {
throw new IllegalArgumentException("name is required");
}
if (url == null || url.trim().isEmpty()) {
throw new IllegalArgumentException("url is required");
}
if (providers == null || providers.isEmpty()) {
throw new IllegalArgumentException("at least one provider is required");
}
return new CreateDestinationRequest(this);
}
}
}