io.soffa.foundation.support.email.model.Email Maven / Gradle / Ivy
package io.soffa.foundation.support.email.model;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.soffa.foundation.core.models.EmailAddress;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import java.util.Collections;
import java.util.List;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class Email {
private String subject;
private EmailAddress sender;
private List to;
private List cc;
private List bcc;
private String textMessage;
private String htmlMessage;
private List attachments;
public Email(String subjet, EmailAddress sender, List to, String textMessage, String htmlMessage) {
this.subject = subjet;
this.sender = sender;
this.to = to;
this.textMessage = textMessage;
this.htmlMessage = htmlMessage;
}
public Email(String subject, List to, String textMessage, String htmlMessage) {
this.subject = subject;
this.to = to;
this.textMessage = textMessage;
this.htmlMessage = htmlMessage;
}
public Email(String subjet, EmailAddress to, String textMessage, String htmlMessage) {
this.subject = subjet;
this.to = Collections.singletonList(to);
this.textMessage = textMessage;
this.htmlMessage = htmlMessage;
}
@JsonIgnore
public boolean hasMessage() {
if (StringUtils.isNotEmpty(textMessage)) {
return true;
}
return StringUtils.isNotEmpty(htmlMessage);
}
}