diff --git a/src/main/java/com/resend/Resend.java b/src/main/java/com/resend/Resend.java index 2016865..bda3613 100644 --- a/src/main/java/com/resend/Resend.java +++ b/src/main/java/com/resend/Resend.java @@ -7,6 +7,7 @@ import com.resend.services.contacts.Contacts; import com.resend.services.domains.Domains; import com.resend.services.emails.Emails; +import com.resend.services.templates.Templates; /** * The Resend class provides a facade for the Domains and Emails services. @@ -89,4 +90,13 @@ public Batch batch() { public Broadcasts broadcasts() { return new Broadcasts(apiKey); } + + /** + * Returns a Templates object that can be used to interact with the Templates service. + * + * @return A Templates object. + */ + public Templates templates() { + return new Templates(apiKey); + } } diff --git a/src/main/java/com/resend/services/templates/Templates.java b/src/main/java/com/resend/services/templates/Templates.java new file mode 100644 index 0000000..14a3c79 --- /dev/null +++ b/src/main/java/com/resend/services/templates/Templates.java @@ -0,0 +1,180 @@ +package com.resend.services.templates; + +import com.resend.core.exception.ResendException; +import com.resend.core.helper.URLHelper; +import com.resend.core.net.AbstractHttpResponse; +import com.resend.core.net.HttpMethod; +import com.resend.core.net.ListParams; +import com.resend.core.service.BaseService; +import com.resend.services.templates.model.*; +import okhttp3.MediaType; + +/** + * Represents the Resend Templates module. + */ +public final class Templates extends BaseService { + + /** + * Constructs an instance of the {@code Templates} class. + * + * @param apiKey The apiKey used for authentication. + */ + public Templates(final String apiKey) { + super(apiKey); + } + + /** + * Creates a new template. + * + * @param options The options for creating the template. + * @return The response indicating the status of the template creation. + * @throws ResendException If an error occurs while creating the template. + */ + public CreateTemplateResponseSuccess create(CreateTemplateOptions options) throws ResendException { + String payload = super.resendMapper.writeValue(options); + AbstractHttpResponse response = super.httpClient.perform("/templates", super.apiKey, HttpMethod.POST, payload, MediaType.get("application/json")); + + if (!response.isSuccessful()) { + throw new ResendException(response.getCode(), response.getBody()); + } + + String responseBody = response.getBody(); + + return resendMapper.readValue(responseBody, CreateTemplateResponseSuccess.class); + } + + /** + * Retrieves a template by its unique identifier or alias. + * + * @param templateId The unique identifier or alias of the template. + * @return The retrieved template's details. + * @throws ResendException If an error occurs while retrieving the template. + */ + public GetTemplateResponseSuccess get(String templateId) throws ResendException { + AbstractHttpResponse response = this.httpClient.perform("/templates/" + templateId, super.apiKey, HttpMethod.GET, null, MediaType.get("application/json")); + + if (!response.isSuccessful()) { + throw new ResendException(response.getCode(), response.getBody()); + } + + String responseBody = response.getBody(); + + return resendMapper.readValue(responseBody, GetTemplateResponseSuccess.class); + } + + /** + * Retrieves a list of templates. + * + * @return A ListTemplatesResponse containing the list of templates. + * @throws ResendException If an error occurs during the templates list retrieval process. + */ + public ListTemplatesResponseSuccess list() throws ResendException { + AbstractHttpResponse response = this.httpClient.perform("/templates", super.apiKey, HttpMethod.GET, null, MediaType.get("application/json")); + + if (!response.isSuccessful()) { + throw new ResendException(response.getCode(), response.getBody()); + } + + String responseBody = response.getBody(); + + return resendMapper.readValue(responseBody, ListTemplatesResponseSuccess.class); + } + + /** + * Retrieves a paginated list of templates. + * + * @param params The params used to customize the list. + * @return A ListTemplatesResponse containing the paginated list of templates. + * @throws ResendException If an error occurs during the templates list retrieval process. + */ + public ListTemplatesResponseSuccess list(ListParams params) throws ResendException { + String pathWithQuery = "/templates" + URLHelper.parse(params); + AbstractHttpResponse response = this.httpClient.perform(pathWithQuery, super.apiKey, HttpMethod.GET, null, MediaType.get("application/json")); + + if (!response.isSuccessful()) { + throw new ResendException(response.getCode(), response.getBody()); + } + + String responseBody = response.getBody(); + + return resendMapper.readValue(responseBody, ListTemplatesResponseSuccess.class); + } + + /** + * Updates a template by its unique identifier or alias. + * + * @param templateId The unique identifier or alias of the template. + * @param options The options for updating the template. + * @return The response indicating the status of the template update. + * @throws ResendException If an error occurs while updating the template. + */ + public UpdateTemplateResponseSuccess update(String templateId, UpdateTemplateOptions options) throws ResendException { + String payload = super.resendMapper.writeValue(options); + AbstractHttpResponse response = this.httpClient.perform("/templates/" + templateId, super.apiKey, HttpMethod.PATCH, payload, MediaType.get("application/json")); + + if (!response.isSuccessful()) { + throw new ResendException(response.getCode(), response.getBody()); + } + + String responseBody = response.getBody(); + + return resendMapper.readValue(responseBody, UpdateTemplateResponseSuccess.class); + } + + /** + * Deletes a template by its unique identifier or alias. + * + * @param templateId The unique identifier or alias of the template. + * @return The response indicating the status of the template deletion. + * @throws ResendException If an error occurs while deleting the template. + */ + public DeleteTemplateResponseSuccess remove(String templateId) throws ResendException { + AbstractHttpResponse response = this.httpClient.perform("/templates/" + templateId, super.apiKey, HttpMethod.DELETE, null, MediaType.get("application/json")); + + if (!response.isSuccessful()) { + throw new ResendException(response.getCode(), response.getBody()); + } + + String responseBody = response.getBody(); + + return resendMapper.readValue(responseBody, DeleteTemplateResponseSuccess.class); + } + + /** + * Duplicates a template by its unique identifier or alias. + * + * @param templateId The unique identifier or alias of the template. + * @return The response indicating the status of the template duplication. + * @throws ResendException If an error occurs while duplicating the template. + */ + public DuplicateTemplateResponseSuccess duplicate(String templateId) throws ResendException { + AbstractHttpResponse response = this.httpClient.perform("/templates/" + templateId + "/duplicate", super.apiKey, HttpMethod.POST, "", MediaType.get("application/json")); + + if (!response.isSuccessful()) { + throw new ResendException(response.getCode(), response.getBody()); + } + + String responseBody = response.getBody(); + + return resendMapper.readValue(responseBody, DuplicateTemplateResponseSuccess.class); + } + + /** + * Publishes a template by its unique identifier or alias. + * + * @param templateId The unique identifier or alias of the template. + * @return The response indicating the status of the template publication. + * @throws ResendException If an error occurs while publishing the template. + */ + public PublishTemplateResponseSuccess publish(String templateId) throws ResendException { + AbstractHttpResponse response = this.httpClient.perform("/templates/" + templateId + "/publish", super.apiKey, HttpMethod.POST, "", MediaType.get("application/json")); + + if (!response.isSuccessful()) { + throw new ResendException(response.getCode(), response.getBody()); + } + + String responseBody = response.getBody(); + + return resendMapper.readValue(responseBody, PublishTemplateResponseSuccess.class); + } +} diff --git a/src/main/java/com/resend/services/templates/model/CreateTemplateOptions.java b/src/main/java/com/resend/services/templates/model/CreateTemplateOptions.java new file mode 100644 index 0000000..702ed87 --- /dev/null +++ b/src/main/java/com/resend/services/templates/model/CreateTemplateOptions.java @@ -0,0 +1,301 @@ +package com.resend.services.templates.model; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.ArrayList; +import java.util.List; + +/** + * Represents options for creating a template. + */ +@JsonInclude(JsonInclude.Include.NON_NULL) +public class CreateTemplateOptions { + + @JsonProperty("name") + private final String name; + + @JsonProperty("alias") + private final String alias; + + @JsonProperty("from") + private final String from; + + @JsonProperty("subject") + private final String subject; + + @JsonProperty("reply_to") + private final List replyTo; + + @JsonProperty("html") + private final String html; + + @JsonProperty("text") + private final String text; + + @JsonProperty("variables") + private final List variables; + + private CreateTemplateOptions(Builder builder) { + this.name = builder.name; + this.alias = builder.alias; + this.from = builder.from; + this.subject = builder.subject; + this.replyTo = builder.replyTo; + this.html = builder.html; + this.text = builder.text; + this.variables = builder.variables; + } + + /** + * Gets the name of the template. + * + * @return The name of the template. + */ + public String getName() { + return name; + } + + /** + * Gets the alias of the template. + * + * @return The alias of the template. + */ + public String getAlias() { + return alias; + } + + /** + * Gets the sender email address. + * + * @return The sender email address. + */ + public String getFrom() { + return from; + } + + /** + * Gets the email subject. + * + * @return The email subject. + */ + public String getSubject() { + return subject; + } + + /** + * Gets the reply-to email addresses. + * + * @return The reply-to email addresses. + */ + public List getReplyTo() { + return replyTo; + } + + /** + * Gets the HTML version of the template. + * + * @return The HTML version of the template. + */ + public String getHtml() { + return html; + } + + /** + * Gets the plain text version of the template. + * + * @return The plain text version of the template. + */ + public String getText() { + return text; + } + + /** + * Gets the list of variables used in the template. + * + * @return The list of variables. + */ + public List getVariables() { + return variables; + } + + /** + * Creates a new builder instance to construct CreateTemplateOptions. + * + * @return A new builder instance. + */ + public static Builder builder() { + return new Builder(); + } + + /** + * Builder class for constructing CreateTemplateOptions instances. + */ + public static class Builder { + private String name; + private String alias; + private String from; + private String subject; + private List replyTo; + private String html; + private String text; + private List variables; + + /** + * Sets the name of the template. + * + * @param name The name of the template. + * @return This builder instance for method chaining. + */ + public Builder name(String name) { + this.name = name; + return this; + } + + /** + * Sets the alias of the template. + * + * @param alias The alias of the template. + * @return This builder instance for method chaining. + */ + public Builder alias(String alias) { + this.alias = alias; + return this; + } + + /** + * Sets the sender email address. + * + * @param from The sender email address. + * @return This builder instance for method chaining. + */ + public Builder from(String from) { + this.from = from; + return this; + } + + /** + * Sets the email subject. + * + * @param subject The email subject. + * @return This builder instance for method chaining. + */ + public Builder subject(String subject) { + this.subject = subject; + return this; + } + + /** + * Sets the reply-to email addresses. + * + * @param replyTo The reply-to email addresses. + * @return This builder instance for method chaining. + */ + public Builder replyTo(String... replyTo) { + if (this.replyTo == null) { + this.replyTo = new ArrayList<>(); + } + for (String email : replyTo) { + this.replyTo.add(email); + } + return this; + } + + /** + * Sets the reply-to email addresses. + * + * @param replyTo The reply-to email addresses. + * @return This builder instance for method chaining. + */ + public Builder replyTo(List replyTo) { + this.replyTo = replyTo; + return this; + } + + /** + * Adds a single reply-to email address. + * + * @param email The reply-to email address to add. + * @return This builder instance for method chaining. + */ + public Builder addReplyTo(String email) { + if (this.replyTo == null) { + this.replyTo = new ArrayList<>(); + } + this.replyTo.add(email); + return this; + } + + /** + * Sets the HTML version of the template. + * + * @param html The HTML version of the template. + * @return This builder instance for method chaining. + */ + public Builder html(String html) { + this.html = html; + return this; + } + + /** + * Sets the plain text version of the template. + * + * @param text The plain text version of the template. + * @return This builder instance for method chaining. + */ + public Builder text(String text) { + this.text = text; + return this; + } + + /** + * Sets the list of variables used in the template. + * + * @param variables The list of variables. + * @return This builder instance for method chaining. + */ + public Builder variables(Variable... variables) { + if (this.variables == null) { + this.variables = new ArrayList<>(); + } + for (Variable variable : variables) { + this.variables.add(variable); + } + return this; + } + + /** + * Sets the list of variables used in the template. + * + * @param variables The list of variables. + * @return This builder instance for method chaining. + */ + public Builder variables(List variables) { + this.variables = variables; + return this; + } + + /** + * Adds a single variable to the template. + * + * @param variable The variable to add. + * @return This builder instance for method chaining. + */ + public Builder addVariable(Variable variable) { + if (this.variables == null) { + this.variables = new ArrayList<>(); + } + this.variables.add(variable); + return this; + } + + /** + * Builds and returns a CreateTemplateOptions instance. + * + * @return A CreateTemplateOptions instance. + */ + public CreateTemplateOptions build() { + return new CreateTemplateOptions(this); + } + } +} diff --git a/src/main/java/com/resend/services/templates/model/CreateTemplateResponseSuccess.java b/src/main/java/com/resend/services/templates/model/CreateTemplateResponseSuccess.java new file mode 100644 index 0000000..c916a12 --- /dev/null +++ b/src/main/java/com/resend/services/templates/model/CreateTemplateResponseSuccess.java @@ -0,0 +1,68 @@ +package com.resend.services.templates.model; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Represents the response from creating a template. + */ +public class CreateTemplateResponseSuccess { + + @JsonProperty("id") + private String id; + + @JsonProperty("object") + private String object; + + /** + * Default constructor. + */ + public CreateTemplateResponseSuccess() { + } + + /** + * Constructs a CreateTemplateResponse with the specified attributes. + * + * @param id The ID of the created template. + * @param object The object type. + */ + public CreateTemplateResponseSuccess(String id, String object) { + this.id = id; + this.object = object; + } + + /** + * Gets the ID of the created template. + * + * @return The ID of the created template. + */ + public String getId() { + return id; + } + + /** + * Sets the ID of the created template. + * + * @param id The ID of the created template. + */ + public void setId(String id) { + this.id = id; + } + + /** + * Gets the object type. + * + * @return The object type. + */ + public String getObject() { + return object; + } + + /** + * Sets the object type. + * + * @param object The object type. + */ + public void setObject(String object) { + this.object = object; + } +} diff --git a/src/main/java/com/resend/services/templates/model/DeleteTemplateResponseSuccess.java b/src/main/java/com/resend/services/templates/model/DeleteTemplateResponseSuccess.java new file mode 100644 index 0000000..049a7b2 --- /dev/null +++ b/src/main/java/com/resend/services/templates/model/DeleteTemplateResponseSuccess.java @@ -0,0 +1,91 @@ +package com.resend.services.templates.model; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Represents the response from deleting a template. + */ +public class DeleteTemplateResponseSuccess { + + @JsonProperty("object") + private String object; + + @JsonProperty("id") + private String id; + + @JsonProperty("deleted") + private Boolean deleted; + + /** + * Default constructor. + */ + public DeleteTemplateResponseSuccess() { + } + + /** + * Constructs a DeleteTemplateResponse with the specified attributes. + * + * @param object The object type. + * @param id The ID of the deleted template. + * @param deleted Whether the template was deleted. + */ + public DeleteTemplateResponseSuccess(String object, String id, Boolean deleted) { + this.object = object; + this.id = id; + this.deleted = deleted; + } + + /** + * Gets the object type. + * + * @return The object type. + */ + public String getObject() { + return object; + } + + /** + * Sets the object type. + * + * @param object The object type. + */ + public void setObject(String object) { + this.object = object; + } + + /** + * Gets the ID of the deleted template. + * + * @return The ID of the deleted template. + */ + public String getId() { + return id; + } + + /** + * Sets the ID of the deleted template. + * + * @param id The ID of the deleted template. + */ + public void setId(String id) { + this.id = id; + } + + /** + * Gets whether the template was deleted. + * + * @return Whether the template was deleted. + */ + public Boolean getDeleted() { + return deleted; + } + + /** + * Sets whether the template was deleted. + * + * @param deleted Whether the template was deleted. + */ + public void setDeleted(Boolean deleted) { + this.deleted = deleted; + } +} diff --git a/src/main/java/com/resend/services/templates/model/DuplicateTemplateResponseSuccess.java b/src/main/java/com/resend/services/templates/model/DuplicateTemplateResponseSuccess.java new file mode 100644 index 0000000..df89fe7 --- /dev/null +++ b/src/main/java/com/resend/services/templates/model/DuplicateTemplateResponseSuccess.java @@ -0,0 +1,68 @@ +package com.resend.services.templates.model; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Represents the response from duplicating a template. + */ +public class DuplicateTemplateResponseSuccess { + + @JsonProperty("object") + private String object; + + @JsonProperty("id") + private String id; + + /** + * Default constructor. + */ + public DuplicateTemplateResponseSuccess() { + } + + /** + * Constructs a DuplicateTemplateResponse with the specified attributes. + * + * @param object The object type. + * @param id The ID of the duplicated template. + */ + public DuplicateTemplateResponseSuccess(String object, String id) { + this.object = object; + this.id = id; + } + + /** + * Gets the object type. + * + * @return The object type. + */ + public String getObject() { + return object; + } + + /** + * Sets the object type. + * + * @param object The object type. + */ + public void setObject(String object) { + this.object = object; + } + + /** + * Gets the ID of the duplicated template. + * + * @return The ID of the duplicated template. + */ + public String getId() { + return id; + } + + /** + * Sets the ID of the duplicated template. + * + * @param id The ID of the duplicated template. + */ + public void setId(String id) { + this.id = id; + } +} diff --git a/src/main/java/com/resend/services/templates/model/GetTemplateResponseSuccess.java b/src/main/java/com/resend/services/templates/model/GetTemplateResponseSuccess.java new file mode 100644 index 0000000..7935416 --- /dev/null +++ b/src/main/java/com/resend/services/templates/model/GetTemplateResponseSuccess.java @@ -0,0 +1,311 @@ +package com.resend.services.templates.model; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.List; + +/** + * Represents a complete template object. + */ +public class GetTemplateResponseSuccess { + + @JsonProperty("object") + private String object; + + @JsonProperty("id") + private String id; + + @JsonProperty("alias") + private String alias; + + @JsonProperty("name") + private String name; + + @JsonProperty("created_at") + private String createdAt; + + @JsonProperty("updated_at") + private String updatedAt; + + @JsonProperty("status") + private String status; + + @JsonProperty("published_at") + private String publishedAt; + + @JsonProperty("from") + private String from; + + @JsonProperty("subject") + private String subject; + + @JsonProperty("reply_to") + private List replyTo; + + @JsonProperty("html") + private String html; + + @JsonProperty("text") + private String text; + + @JsonProperty("variables") + private List variables; + + /** + * Default constructor. + */ + public GetTemplateResponseSuccess() { + } + + /** + * Gets the object type. + * + * @return The object type. + */ + public String getObject() { + return object; + } + + /** + * Sets the object type. + * + * @param object The object type. + */ + public void setObject(String object) { + this.object = object; + } + + /** + * Gets the ID of the template. + * + * @return The ID of the template. + */ + public String getId() { + return id; + } + + /** + * Sets the ID of the template. + * + * @param id The ID of the template. + */ + public void setId(String id) { + this.id = id; + } + + /** + * Gets the alias of the template. + * + * @return The alias of the template. + */ + public String getAlias() { + return alias; + } + + /** + * Sets the alias of the template. + * + * @param alias The alias of the template. + */ + public void setAlias(String alias) { + this.alias = alias; + } + + /** + * Gets the name of the template. + * + * @return The name of the template. + */ + public String getName() { + return name; + } + + /** + * Sets the name of the template. + * + * @param name The name of the template. + */ + public void setName(String name) { + this.name = name; + } + + /** + * Gets the creation timestamp of the template. + * + * @return The creation timestamp. + */ + public String getCreatedAt() { + return createdAt; + } + + /** + * Sets the creation timestamp of the template. + * + * @param createdAt The creation timestamp. + */ + public void setCreatedAt(String createdAt) { + this.createdAt = createdAt; + } + + /** + * Gets the last update timestamp of the template. + * + * @return The last update timestamp. + */ + public String getUpdatedAt() { + return updatedAt; + } + + /** + * Sets the last update timestamp of the template. + * + * @param updatedAt The last update timestamp. + */ + public void setUpdatedAt(String updatedAt) { + this.updatedAt = updatedAt; + } + + /** + * Gets the status of the template. + * + * @return The status of the template. + */ + public String getStatus() { + return status; + } + + /** + * Sets the status of the template. + * + * @param status The status of the template. + */ + public void setStatus(String status) { + this.status = status; + } + + /** + * Gets the publication timestamp of the template. + * + * @return The publication timestamp. + */ + public String getPublishedAt() { + return publishedAt; + } + + /** + * Sets the publication timestamp of the template. + * + * @param publishedAt The publication timestamp. + */ + public void setPublishedAt(String publishedAt) { + this.publishedAt = publishedAt; + } + + /** + * Gets the sender email address. + * + * @return The sender email address. + */ + public String getFrom() { + return from; + } + + /** + * Sets the sender email address. + * + * @param from The sender email address. + */ + public void setFrom(String from) { + this.from = from; + } + + /** + * Gets the email subject. + * + * @return The email subject. + */ + public String getSubject() { + return subject; + } + + /** + * Sets the email subject. + * + * @param subject The email subject. + */ + public void setSubject(String subject) { + this.subject = subject; + } + + /** + * Gets the reply-to email addresses. + * + * @return The reply-to email addresses. + */ + public List getReplyTo() { + return replyTo; + } + + /** + * Sets the reply-to email addresses. + * + * @param replyTo The reply-to email addresses. + */ + public void setReplyTo(List replyTo) { + this.replyTo = replyTo; + } + + /** + * Gets the HTML version of the template. + * + * @return The HTML version of the template. + */ + public String getHtml() { + return html; + } + + /** + * Sets the HTML version of the template. + * + * @param html The HTML version of the template. + */ + public void setHtml(String html) { + this.html = html; + } + + /** + * Gets the plain text version of the template. + * + * @return The plain text version of the template. + */ + public String getText() { + return text; + } + + /** + * Sets the plain text version of the template. + * + * @param text The plain text version of the template. + */ + public void setText(String text) { + this.text = text; + } + + /** + * Gets the list of variables used in the template. + * + * @return The list of variables. + */ + public List getVariables() { + return variables; + } + + /** + * Sets the list of variables used in the template. + * + * @param variables The list of variables. + */ + public void setVariables(List variables) { + this.variables = variables; + } +} diff --git a/src/main/java/com/resend/services/templates/model/ListTemplatesResponseSuccess.java b/src/main/java/com/resend/services/templates/model/ListTemplatesResponseSuccess.java new file mode 100644 index 0000000..4278a2b --- /dev/null +++ b/src/main/java/com/resend/services/templates/model/ListTemplatesResponseSuccess.java @@ -0,0 +1,93 @@ +package com.resend.services.templates.model; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.List; + +/** + * Represents the response from listing templates. + */ +public class ListTemplatesResponseSuccess { + + @JsonProperty("object") + private String object; + + @JsonProperty("data") + private List data; + + @JsonProperty("has_more") + private Boolean hasMore; + + /** + * Default constructor. + */ + public ListTemplatesResponseSuccess() { + } + + /** + * Constructs a ListTemplatesResponse with the specified attributes. + * + * @param object The object type. + * @param data The list of templates. + * @param hasMore Whether there are more templates available. + */ + public ListTemplatesResponseSuccess(String object, List data, Boolean hasMore) { + this.object = object; + this.data = data; + this.hasMore = hasMore; + } + + /** + * Gets the object type. + * + * @return The object type. + */ + public String getObject() { + return object; + } + + /** + * Sets the object type. + * + * @param object The object type. + */ + public void setObject(String object) { + this.object = object; + } + + /** + * Gets the list of templates. + * + * @return The list of templates. + */ + public List getData() { + return data; + } + + /** + * Sets the list of templates. + * + * @param data The list of templates. + */ + public void setData(List data) { + this.data = data; + } + + /** + * Gets whether there are more templates available. + * + * @return Whether there are more templates available. + */ + public Boolean getHasMore() { + return hasMore; + } + + /** + * Sets whether there are more templates available. + * + * @param hasMore Whether there are more templates available. + */ + public void setHasMore(Boolean hasMore) { + this.hasMore = hasMore; + } +} diff --git a/src/main/java/com/resend/services/templates/model/PublishTemplateResponseSuccess.java b/src/main/java/com/resend/services/templates/model/PublishTemplateResponseSuccess.java new file mode 100644 index 0000000..41d45ca --- /dev/null +++ b/src/main/java/com/resend/services/templates/model/PublishTemplateResponseSuccess.java @@ -0,0 +1,68 @@ +package com.resend.services.templates.model; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Represents the response from publishing a template. + */ +public class PublishTemplateResponseSuccess { + + @JsonProperty("id") + private String id; + + @JsonProperty("object") + private String object; + + /** + * Default constructor. + */ + public PublishTemplateResponseSuccess() { + } + + /** + * Constructs a PublishTemplateResponse with the specified attributes. + * + * @param id The ID of the published template. + * @param object The object type. + */ + public PublishTemplateResponseSuccess(String id, String object) { + this.id = id; + this.object = object; + } + + /** + * Gets the ID of the published template. + * + * @return The ID of the published template. + */ + public String getId() { + return id; + } + + /** + * Sets the ID of the published template. + * + * @param id The ID of the published template. + */ + public void setId(String id) { + this.id = id; + } + + /** + * Gets the object type. + * + * @return The object type. + */ + public String getObject() { + return object; + } + + /** + * Sets the object type. + * + * @param object The object type. + */ + public void setObject(String object) { + this.object = object; + } +} diff --git a/src/main/java/com/resend/services/templates/model/TemplateListItem.java b/src/main/java/com/resend/services/templates/model/TemplateListItem.java new file mode 100644 index 0000000..951084a --- /dev/null +++ b/src/main/java/com/resend/services/templates/model/TemplateListItem.java @@ -0,0 +1,162 @@ +package com.resend.services.templates.model; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Represents a template item in a list response. + */ +public class TemplateListItem { + + @JsonProperty("id") + private String id; + + @JsonProperty("name") + private String name; + + @JsonProperty("status") + private String status; + + @JsonProperty("published_at") + private String publishedAt; + + @JsonProperty("created_at") + private String createdAt; + + @JsonProperty("updated_at") + private String updatedAt; + + @JsonProperty("alias") + private String alias; + + /** + * Default constructor. + */ + public TemplateListItem() { + } + + /** + * Gets the ID of the template. + * + * @return The ID of the template. + */ + public String getId() { + return id; + } + + /** + * Sets the ID of the template. + * + * @param id The ID of the template. + */ + public void setId(String id) { + this.id = id; + } + + /** + * Gets the name of the template. + * + * @return The name of the template. + */ + public String getName() { + return name; + } + + /** + * Sets the name of the template. + * + * @param name The name of the template. + */ + public void setName(String name) { + this.name = name; + } + + /** + * Gets the status of the template. + * + * @return The status of the template. + */ + public String getStatus() { + return status; + } + + /** + * Sets the status of the template. + * + * @param status The status of the template. + */ + public void setStatus(String status) { + this.status = status; + } + + /** + * Gets the publication timestamp of the template. + * + * @return The publication timestamp. + */ + public String getPublishedAt() { + return publishedAt; + } + + /** + * Sets the publication timestamp of the template. + * + * @param publishedAt The publication timestamp. + */ + public void setPublishedAt(String publishedAt) { + this.publishedAt = publishedAt; + } + + /** + * Gets the creation timestamp of the template. + * + * @return The creation timestamp. + */ + public String getCreatedAt() { + return createdAt; + } + + /** + * Sets the creation timestamp of the template. + * + * @param createdAt The creation timestamp. + */ + public void setCreatedAt(String createdAt) { + this.createdAt = createdAt; + } + + /** + * Gets the last update timestamp of the template. + * + * @return The last update timestamp. + */ + public String getUpdatedAt() { + return updatedAt; + } + + /** + * Sets the last update timestamp of the template. + * + * @param updatedAt The last update timestamp. + */ + public void setUpdatedAt(String updatedAt) { + this.updatedAt = updatedAt; + } + + /** + * Gets the alias of the template. + * + * @return The alias of the template. + */ + public String getAlias() { + return alias; + } + + /** + * Sets the alias of the template. + * + * @param alias The alias of the template. + */ + public void setAlias(String alias) { + this.alias = alias; + } +} diff --git a/src/main/java/com/resend/services/templates/model/UpdateTemplateOptions.java b/src/main/java/com/resend/services/templates/model/UpdateTemplateOptions.java new file mode 100644 index 0000000..e643108 --- /dev/null +++ b/src/main/java/com/resend/services/templates/model/UpdateTemplateOptions.java @@ -0,0 +1,301 @@ +package com.resend.services.templates.model; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.ArrayList; +import java.util.List; + +/** + * Represents options for updating a template. + */ +@JsonInclude(JsonInclude.Include.NON_NULL) +public class UpdateTemplateOptions { + + @JsonProperty("name") + private final String name; + + @JsonProperty("alias") + private final String alias; + + @JsonProperty("from") + private final String from; + + @JsonProperty("subject") + private final String subject; + + @JsonProperty("reply_to") + private final List replyTo; + + @JsonProperty("html") + private final String html; + + @JsonProperty("text") + private final String text; + + @JsonProperty("variables") + private final List variables; + + private UpdateTemplateOptions(Builder builder) { + this.name = builder.name; + this.alias = builder.alias; + this.from = builder.from; + this.subject = builder.subject; + this.replyTo = builder.replyTo; + this.html = builder.html; + this.text = builder.text; + this.variables = builder.variables; + } + + /** + * Gets the name of the template. + * + * @return The name of the template. + */ + public String getName() { + return name; + } + + /** + * Gets the alias of the template. + * + * @return The alias of the template. + */ + public String getAlias() { + return alias; + } + + /** + * Gets the sender email address. + * + * @return The sender email address. + */ + public String getFrom() { + return from; + } + + /** + * Gets the email subject. + * + * @return The email subject. + */ + public String getSubject() { + return subject; + } + + /** + * Gets the reply-to email addresses. + * + * @return The reply-to email addresses. + */ + public List getReplyTo() { + return replyTo; + } + + /** + * Gets the HTML version of the template. + * + * @return The HTML version of the template. + */ + public String getHtml() { + return html; + } + + /** + * Gets the plain text version of the template. + * + * @return The plain text version of the template. + */ + public String getText() { + return text; + } + + /** + * Gets the list of variables used in the template. + * + * @return The list of variables. + */ + public List getVariables() { + return variables; + } + + /** + * Creates a new builder instance to construct UpdateTemplateOptions. + * + * @return A new builder instance. + */ + public static Builder builder() { + return new Builder(); + } + + /** + * Builder class for constructing UpdateTemplateOptions instances. + */ + public static class Builder { + private String name; + private String alias; + private String from; + private String subject; + private List replyTo; + private String html; + private String text; + private List variables; + + /** + * Sets the name of the template. + * + * @param name The name of the template. + * @return This builder instance for method chaining. + */ + public Builder name(String name) { + this.name = name; + return this; + } + + /** + * Sets the alias of the template. + * + * @param alias The alias of the template. + * @return This builder instance for method chaining. + */ + public Builder alias(String alias) { + this.alias = alias; + return this; + } + + /** + * Sets the sender email address. + * + * @param from The sender email address. + * @return This builder instance for method chaining. + */ + public Builder from(String from) { + this.from = from; + return this; + } + + /** + * Sets the email subject. + * + * @param subject The email subject. + * @return This builder instance for method chaining. + */ + public Builder subject(String subject) { + this.subject = subject; + return this; + } + + /** + * Sets the reply-to email addresses. + * + * @param replyTo The reply-to email addresses. + * @return This builder instance for method chaining. + */ + public Builder replyTo(String... replyTo) { + if (this.replyTo == null) { + this.replyTo = new ArrayList<>(); + } + for (String email : replyTo) { + this.replyTo.add(email); + } + return this; + } + + /** + * Sets the reply-to email addresses. + * + * @param replyTo The reply-to email addresses. + * @return This builder instance for method chaining. + */ + public Builder replyTo(List replyTo) { + this.replyTo = replyTo; + return this; + } + + /** + * Adds a single reply-to email address. + * + * @param email The reply-to email address to add. + * @return This builder instance for method chaining. + */ + public Builder addReplyTo(String email) { + if (this.replyTo == null) { + this.replyTo = new ArrayList<>(); + } + this.replyTo.add(email); + return this; + } + + /** + * Sets the HTML version of the template. + * + * @param html The HTML version of the template. + * @return This builder instance for method chaining. + */ + public Builder html(String html) { + this.html = html; + return this; + } + + /** + * Sets the plain text version of the template. + * + * @param text The plain text version of the template. + * @return This builder instance for method chaining. + */ + public Builder text(String text) { + this.text = text; + return this; + } + + /** + * Sets the list of variables used in the template. + * + * @param variables The list of variables. + * @return This builder instance for method chaining. + */ + public Builder variables(Variable... variables) { + if (this.variables == null) { + this.variables = new ArrayList<>(); + } + for (Variable variable : variables) { + this.variables.add(variable); + } + return this; + } + + /** + * Sets the list of variables used in the template. + * + * @param variables The list of variables. + * @return This builder instance for method chaining. + */ + public Builder variables(List variables) { + this.variables = variables; + return this; + } + + /** + * Adds a single variable to the template. + * + * @param variable The variable to add. + * @return This builder instance for method chaining. + */ + public Builder addVariable(Variable variable) { + if (this.variables == null) { + this.variables = new ArrayList<>(); + } + this.variables.add(variable); + return this; + } + + /** + * Builds and returns an UpdateTemplateOptions instance. + * + * @return An UpdateTemplateOptions instance. + */ + public UpdateTemplateOptions build() { + return new UpdateTemplateOptions(this); + } + } +} diff --git a/src/main/java/com/resend/services/templates/model/UpdateTemplateResponseSuccess.java b/src/main/java/com/resend/services/templates/model/UpdateTemplateResponseSuccess.java new file mode 100644 index 0000000..e278fe4 --- /dev/null +++ b/src/main/java/com/resend/services/templates/model/UpdateTemplateResponseSuccess.java @@ -0,0 +1,68 @@ +package com.resend.services.templates.model; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Represents the response from updating a template. + */ +public class UpdateTemplateResponseSuccess { + + @JsonProperty("id") + private String id; + + @JsonProperty("object") + private String object; + + /** + * Default constructor. + */ + public UpdateTemplateResponseSuccess() { + } + + /** + * Constructs an UpdateTemplateResponse with the specified attributes. + * + * @param id The ID of the updated template. + * @param object The object type. + */ + public UpdateTemplateResponseSuccess(String id, String object) { + this.id = id; + this.object = object; + } + + /** + * Gets the ID of the updated template. + * + * @return The ID of the updated template. + */ + public String getId() { + return id; + } + + /** + * Sets the ID of the updated template. + * + * @param id The ID of the updated template. + */ + public void setId(String id) { + this.id = id; + } + + /** + * Gets the object type. + * + * @return The object type. + */ + public String getObject() { + return object; + } + + /** + * Sets the object type. + * + * @param object The object type. + */ + public void setObject(String object) { + this.object = object; + } +} diff --git a/src/main/java/com/resend/services/templates/model/Variable.java b/src/main/java/com/resend/services/templates/model/Variable.java new file mode 100644 index 0000000..b4627f1 --- /dev/null +++ b/src/main/java/com/resend/services/templates/model/Variable.java @@ -0,0 +1,231 @@ +package com.resend.services.templates.model; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Represents a variable in a template. + */ +@JsonInclude(JsonInclude.Include.NON_NULL) +public class Variable { + + @JsonProperty("id") + private String id; + + @JsonProperty("key") + private String key; + + @JsonProperty("type") + private VariableType type; + + @JsonProperty("fallback_value") + private Object fallbackValue; + + @JsonProperty("created_at") + private String createdAt; + + @JsonProperty("updated_at") + private String updatedAt; + + /** + * Default constructor. + */ + public Variable() { + } + + /** + * Constructs a Variable with the specified key and type. + * + * @param key The key of the variable. + * @param type The type of the variable. + */ + public Variable(String key, VariableType type) { + this.key = key; + this.type = type; + } + + /** + * Constructs a Variable with the specified key, type, and fallback value. + * + * @param key The key of the variable. + * @param type The type of the variable. + * @param fallbackValue The fallback value of the variable. + */ + public Variable(String key, VariableType type, Object fallbackValue) { + this.key = key; + this.type = type; + this.fallbackValue = fallbackValue; + } + + /** + * Gets the ID of the variable. + * + * @return The ID of the variable. + */ + public String getId() { + return id; + } + + /** + * Sets the ID of the variable. + * + * @param id The ID of the variable. + */ + public void setId(String id) { + this.id = id; + } + + /** + * Gets the key of the variable. + * + * @return The key of the variable. + */ + public String getKey() { + return key; + } + + /** + * Sets the key of the variable. + * + * @param key The key of the variable. + */ + public void setKey(String key) { + this.key = key; + } + + /** + * Gets the type of the variable. + * + * @return The type of the variable. + */ + public VariableType getType() { + return type; + } + + /** + * Sets the type of the variable. + * + * @param type The type of the variable. + */ + public void setType(VariableType type) { + this.type = type; + } + + /** + * Gets the fallback value of the variable. + * + * @return The fallback value of the variable. + */ + public Object getFallbackValue() { + return fallbackValue; + } + + /** + * Sets the fallback value of the variable. + * + * @param fallbackValue The fallback value of the variable. + */ + public void setFallbackValue(Object fallbackValue) { + this.fallbackValue = fallbackValue; + } + + /** + * Gets the creation timestamp of the variable. + * + * @return The creation timestamp. + */ + public String getCreatedAt() { + return createdAt; + } + + /** + * Sets the creation timestamp of the variable. + * + * @param createdAt The creation timestamp. + */ + public void setCreatedAt(String createdAt) { + this.createdAt = createdAt; + } + + /** + * Gets the last update timestamp of the variable. + * + * @return The last update timestamp. + */ + public String getUpdatedAt() { + return updatedAt; + } + + /** + * Sets the last update timestamp of the variable. + * + * @param updatedAt The last update timestamp. + */ + public void setUpdatedAt(String updatedAt) { + this.updatedAt = updatedAt; + } + + /** + * Creates a new builder instance to construct Variable. + * + * @return A new builder instance. + */ + public static Builder builder() { + return new Builder(); + } + + /** + * Builder class for constructing Variable instances. + */ + public static class Builder { + private String key; + private VariableType type; + private Object fallbackValue; + + /** + * Sets the key of the variable. + * + * @param key The key of the variable. + * @return This builder instance for method chaining. + */ + public Builder key(String key) { + this.key = key; + return this; + } + + /** + * Sets the type of the variable. + * + * @param type The type of the variable. + * @return This builder instance for method chaining. + */ + public Builder type(VariableType type) { + this.type = type; + return this; + } + + /** + * Sets the fallback value of the variable. + * + * @param fallbackValue The fallback value of the variable. + * @return This builder instance for method chaining. + */ + public Builder fallbackValue(Object fallbackValue) { + this.fallbackValue = fallbackValue; + return this; + } + + /** + * Builds and returns a Variable instance. + * + * @return A Variable instance. + */ + public Variable build() { + Variable variable = new Variable(); + variable.key = this.key; + variable.type = this.type; + variable.fallbackValue = this.fallbackValue; + return variable; + } + } +} diff --git a/src/main/java/com/resend/services/templates/model/VariableType.java b/src/main/java/com/resend/services/templates/model/VariableType.java new file mode 100644 index 0000000..0699898 --- /dev/null +++ b/src/main/java/com/resend/services/templates/model/VariableType.java @@ -0,0 +1,34 @@ +package com.resend.services.templates.model; + +import com.fasterxml.jackson.annotation.JsonValue; + +/** + * Enum representing the type of a template variable. + */ +public enum VariableType { + /** + * String type variable. + */ + STRING("string"), + + /** + * Number type variable. + */ + NUMBER("number"); + + private final String value; + + VariableType(String value) { + this.value = value; + } + + /** + * Gets the string value of the variable type. + * + * @return The string value. + */ + @JsonValue + public String getValue() { + return value; + } +} diff --git a/src/test/java/com/resend/services/templates/TemplatesTest.java b/src/test/java/com/resend/services/templates/TemplatesTest.java new file mode 100644 index 0000000..c85e0b1 --- /dev/null +++ b/src/test/java/com/resend/services/templates/TemplatesTest.java @@ -0,0 +1,166 @@ +package com.resend.services.templates; + +import com.resend.core.exception.ResendException; +import com.resend.core.net.ListParams; +import com.resend.services.templates.model.*; +import com.resend.services.util.TemplatesUtil; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.mockito.Mockito.*; + +/** + * Unit tests for the Templates service. + */ +public class TemplatesTest { + + @Mock + private Templates templates; + + @BeforeEach + public void setUp() { + MockitoAnnotations.openMocks(this); + templates = mock(Templates.class); + } + + @Test + public void testCreateTemplate_Success() throws ResendException { + CreateTemplateOptions createOptions = TemplatesUtil.createTemplateOptions(); + CreateTemplateResponseSuccess expectedResponse = TemplatesUtil.createTemplateResponse(); + + when(templates.create(createOptions)).thenReturn(expectedResponse); + + CreateTemplateResponseSuccess response = templates.create(createOptions); + + assertNotNull(response); + assertEquals(expectedResponse.getId(), response.getId()); + assertEquals(expectedResponse.getObject(), response.getObject()); + verify(templates, times(1)).create(createOptions); + } + + @Test + public void testGetTemplate_Success() throws ResendException { + String templateId = "34a080c9-b17d-4187-ad80-5af20266e535"; + GetTemplateResponseSuccess expectedTemplate = TemplatesUtil.createTemplate(); + + when(templates.get(templateId)).thenReturn(expectedTemplate); + + GetTemplateResponseSuccess retrievedTemplate = templates.get(templateId); + + assertNotNull(retrievedTemplate); + assertEquals(expectedTemplate.getId(), retrievedTemplate.getId()); + assertEquals(expectedTemplate.getName(), retrievedTemplate.getName()); + assertEquals(expectedTemplate.getStatus(), retrievedTemplate.getStatus()); + verify(templates, times(1)).get(templateId); + } + + @Test + public void testGetTemplateByAlias_Success() throws ResendException { + String alias = "reset-password"; + GetTemplateResponseSuccess expectedTemplate = TemplatesUtil.createTemplate(); + + when(templates.get(alias)).thenReturn(expectedTemplate); + + GetTemplateResponseSuccess retrievedTemplate = templates.get(alias); + + assertNotNull(retrievedTemplate); + assertEquals(expectedTemplate.getAlias(), retrievedTemplate.getAlias()); + verify(templates, times(1)).get(alias); + } + + @Test + public void testListTemplates_Success() throws ResendException { + ListTemplatesResponseSuccess expectedResponse = TemplatesUtil.listTemplatesResponse(); + + when(templates.list()).thenReturn(expectedResponse); + + ListTemplatesResponseSuccess response = templates.list(); + + assertNotNull(response); + assertEquals(expectedResponse.getData().size(), response.getData().size()); + assertEquals(expectedResponse.getHasMore(), response.getHasMore()); + verify(templates, times(1)).list(); + } + + @Test + public void testListTemplatesWithPagination_Success() throws ResendException { + ListParams params = ListParams.builder() + .limit(2) + .after("34a080c9-b17d-4187-ad80-5af20266e535") + .build(); + ListTemplatesResponseSuccess expectedResponse = TemplatesUtil.listTemplatesResponse(); + + when(templates.list(params)).thenReturn(expectedResponse); + + ListTemplatesResponseSuccess response = templates.list(params); + + assertNotNull(response); + assertEquals(expectedResponse.getData().size(), response.getData().size()); + verify(templates, times(1)).list(params); + } + + @Test + public void testUpdateTemplate_Success() throws ResendException { + String templateId = "34a080c9-b17d-4187-ad80-5af20266e535"; + UpdateTemplateOptions updateOptions = TemplatesUtil.updateTemplateOptions(); + UpdateTemplateResponseSuccess expectedResponse = TemplatesUtil.updateTemplateResponse(); + + when(templates.update(templateId, updateOptions)).thenReturn(expectedResponse); + + UpdateTemplateResponseSuccess response = templates.update(templateId, updateOptions); + + assertNotNull(response); + assertEquals(expectedResponse.getId(), response.getId()); + assertEquals(expectedResponse.getObject(), response.getObject()); + verify(templates, times(1)).update(templateId, updateOptions); + } + + @Test + public void testDeleteTemplate_Success() throws ResendException { + String templateId = "34a080c9-b17d-4187-ad80-5af20266e535"; + DeleteTemplateResponseSuccess expectedResponse = TemplatesUtil.deleteTemplateResponse(); + + when(templates.remove(templateId)).thenReturn(expectedResponse); + + DeleteTemplateResponseSuccess response = templates.remove(templateId); + + assertNotNull(response); + assertEquals(expectedResponse.getId(), response.getId()); + assertEquals(expectedResponse.getDeleted(), response.getDeleted()); + verify(templates, times(1)).remove(templateId); + } + + @Test + public void testDuplicateTemplate_Success() throws ResendException { + String templateId = "34a080c9-b17d-4187-ad80-5af20266e535"; + DuplicateTemplateResponseSuccess expectedResponse = TemplatesUtil.duplicateTemplateResponse(); + + when(templates.duplicate(templateId)).thenReturn(expectedResponse); + + DuplicateTemplateResponseSuccess response = templates.duplicate(templateId); + + assertNotNull(response); + assertEquals(expectedResponse.getId(), response.getId()); + assertEquals(expectedResponse.getObject(), response.getObject()); + verify(templates, times(1)).duplicate(templateId); + } + + @Test + public void testPublishTemplate_Success() throws ResendException { + String templateId = "34a080c9-b17d-4187-ad80-5af20266e535"; + PublishTemplateResponseSuccess expectedResponse = TemplatesUtil.publishTemplateResponse(); + + when(templates.publish(templateId)).thenReturn(expectedResponse); + + PublishTemplateResponseSuccess response = templates.publish(templateId); + + assertNotNull(response); + assertEquals(expectedResponse.getId(), response.getId()); + assertEquals(expectedResponse.getObject(), response.getObject()); + verify(templates, times(1)).publish(templateId); + } +} diff --git a/src/test/java/com/resend/services/util/TemplatesUtil.java b/src/test/java/com/resend/services/util/TemplatesUtil.java new file mode 100644 index 0000000..60e8703 --- /dev/null +++ b/src/test/java/com/resend/services/util/TemplatesUtil.java @@ -0,0 +1,215 @@ +package com.resend.services.util; + +import com.resend.services.templates.model.*; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * Utility class for creating test data for Templates service. + */ +public class TemplatesUtil { + + /** + * Creates a test Variable. + * + * @return A Variable instance for testing. + */ + public static Variable createVariable() { + return Variable.builder() + .key("NAME") + .type(VariableType.STRING) + .fallbackValue("user") + .build(); + } + + /** + * Creates a test Variable with number type. + * + * @return A Variable instance for testing. + */ + public static Variable createNumberVariable() { + return Variable.builder() + .key("AGE") + .type(VariableType.NUMBER) + .fallbackValue(25) + .build(); + } + + /** + * Creates a test Variable without fallback value. + * + * @return A Variable instance for testing. + */ + public static Variable createVariableWithoutFallback() { + return Variable.builder() + .key("OPTIONAL_VARIABLE") + .type(VariableType.STRING) + .build(); + } + + /** + * Creates test CreateTemplateOptions. + * + * @return A CreateTemplateOptions instance for testing. + */ + public static CreateTemplateOptions createTemplateOptions() { + return CreateTemplateOptions.builder() + .name("welcome-email") + .alias("welcome-email-alias") + .from("John Doe ") + .subject("Welcome to our service") + .replyTo("support@example.com") + .html("Hey, {{{NAME}}}, you are {{{AGE}}} years old.") + .text("Hey, NAME, you are AGE years old.") + .variables(Arrays.asList(createVariable(), createNumberVariable(), createVariableWithoutFallback())) + .build(); + } + + /** + * Creates test UpdateTemplateOptions. + * + * @return An UpdateTemplateOptions instance for testing. + */ + public static UpdateTemplateOptions updateTemplateOptions() { + return UpdateTemplateOptions.builder() + .name("updated-welcome-email") + .html("Hello, {{{NAME}}}") + .build(); + } + + /** + * Creates a test CreateTemplateResponse. + * + * @return A CreateTemplateResponse instance for testing. + */ + public static CreateTemplateResponseSuccess createTemplateResponse() { + return new CreateTemplateResponseSuccess("49a3999c-0ce1-4ea6-ab68-afcd6dc2e794", "template"); + } + + /** + * Creates a test DeleteTemplateResponse. + * + * @return A DeleteTemplateResponse instance for testing. + */ + public static DeleteTemplateResponseSuccess deleteTemplateResponse() { + return new DeleteTemplateResponseSuccess("template", "34a080c9-b17d-4187-ad80-5af20266e535", true); + } + + /** + * Creates a test DuplicateTemplateResponse. + * + * @return A DuplicateTemplateResponse instance for testing. + */ + public static DuplicateTemplateResponseSuccess duplicateTemplateResponse() { + return new DuplicateTemplateResponseSuccess("template", "e169aa45-1ecf-4183-9955-b1499d5701d3"); + } + + /** + * Creates a test PublishTemplateResponse. + * + * @return A PublishTemplateResponse instance for testing. + */ + public static PublishTemplateResponseSuccess publishTemplateResponse() { + return new PublishTemplateResponseSuccess("34a080c9-b17d-4187-ad80-5af20266e535", "template"); + } + + /** + * Creates a test UpdateTemplateResponse. + * + * @return An UpdateTemplateResponse instance for testing. + */ + public static UpdateTemplateResponseSuccess updateTemplateResponse() { + return new UpdateTemplateResponseSuccess("34a080c9-b17d-4187-ad80-5af20266e535", "template"); + } + + /** + * Creates a test Template. + * + * @return A Template instance for testing. + */ + public static GetTemplateResponseSuccess createTemplate() { + GetTemplateResponseSuccess template = new GetTemplateResponseSuccess(); + template.setObject("template"); + template.setId("34a080c9-b17d-4187-ad80-5af20266e535"); + template.setAlias("reset-password"); + template.setName("reset-password"); + template.setCreatedAt("2023-10-06T23:47:56.678Z"); + template.setUpdatedAt("2023-10-06T23:47:56.678Z"); + template.setStatus("published"); + template.setPublishedAt("2023-10-06T23:47:56.678Z"); + template.setFrom("John Doe "); + template.setSubject("Hello, world!"); + template.setReplyTo(null); + template.setHtml("

Hello, world!

"); + template.setText("Hello, world!"); + + Variable variable = new Variable(); + variable.setId("e169aa45-1ecf-4183-9955-b1499d5701d3"); + variable.setKey("user_name"); + variable.setType(VariableType.STRING); + variable.setFallbackValue("John Doe"); + variable.setCreatedAt("2023-10-06T23:47:56.678Z"); + variable.setUpdatedAt("2023-10-06T23:47:56.678Z"); + + template.setVariables(Arrays.asList(variable)); + + return template; + } + + /** + * Creates a test TemplateListItem. + * + * @return A TemplateListItem instance for testing. + */ + public static TemplateListItem createTemplateListItem() { + TemplateListItem item = new TemplateListItem(); + item.setId("e169aa45-1ecf-4183-9955-b1499d5701d3"); + item.setName("reset-password"); + item.setStatus("draft"); + item.setPublishedAt(null); + item.setCreatedAt("2023-10-06T23:47:56.678Z"); + item.setUpdatedAt("2023-10-06T23:47:56.678Z"); + item.setAlias("reset-password"); + return item; + } + + /** + * Creates a second test TemplateListItem. + * + * @return A TemplateListItem instance for testing. + */ + public static TemplateListItem createTemplateListItem2() { + TemplateListItem item = new TemplateListItem(); + item.setId("b7f9c2e1-1234-4abc-9def-567890abcdef"); + item.setName("welcome-message"); + item.setStatus("published"); + item.setPublishedAt("2023-10-06T23:47:56.678Z"); + item.setCreatedAt("2023-10-06T23:47:56.678Z"); + item.setUpdatedAt("2023-10-06T23:47:56.678Z"); + item.setAlias("welcome-message"); + return item; + } + + /** + * Creates a list of test TemplateListItems. + * + * @return A list of TemplateListItem instances for testing. + */ + public static List createTemplateList() { + List templates = new ArrayList<>(); + templates.add(createTemplateListItem()); + templates.add(createTemplateListItem2()); + return templates; + } + + /** + * Creates a test ListTemplatesResponse. + * + * @return A ListTemplatesResponse instance for testing. + */ + public static ListTemplatesResponseSuccess listTemplatesResponse() { + return new ListTemplatesResponseSuccess("list", createTemplateList(), false); + } +}