001/*
002 *   Copyright 2024 Vonage
003 *
004 *   Licensed under the Apache License, Version 2.0 (the "License");
005 *   you may not use this file except in compliance with the License.
006 *   You may obtain a copy of the License at
007 *
008 *        http://www.apache.org/licenses/LICENSE-2.0
009 *
010 *   Unless required by applicable law or agreed to in writing, software
011 *   distributed under the License is distributed on an "AS IS" BASIS,
012 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *   See the License for the specific language governing permissions and
014 *   limitations under the License.
015 */
016package com.vonage.client.messages.sms;
017
018import com.fasterxml.jackson.annotation.JsonProperty;
019import com.vonage.client.messages.Channel;
020import com.vonage.client.messages.MessageRequest;
021import com.vonage.client.messages.MessageType;
022import com.vonage.client.messages.TextMessageRequest;
023
024public final class SmsTextRequest extends MessageRequest implements TextMessageRequest {
025        final OutboundSettings sms;
026
027        SmsTextRequest(Builder builder) {
028                super(builder, Channel.SMS, MessageType.TEXT);
029                sms = OutboundSettings.construct(builder.encodingType, builder.contentId, builder.entityId);
030        }
031
032        @Override
033        public String getText() {
034                return super.getText();
035        }
036
037        @JsonProperty("sms")
038        public OutboundSettings getMessageSettings() {
039                return sms;
040        }
041
042        @JsonProperty("ttl")
043        public Integer getTtl() {
044                return ttl;
045        }
046
047        public static Builder builder() {
048                return new Builder();
049        }
050
051        public final static class Builder extends MessageRequest.Builder<SmsTextRequest, Builder> implements TextMessageRequest.Builder<Builder> {
052                String contentId, entityId;
053                EncodingType encodingType;
054
055                Builder() {}
056
057                /**
058                 * (REQUIRED)
059                 * Sets the text field. Must be between 1 and 1000 characters. The Messages API automatically
060                 * detects unicode characters when sending SMS and sends the message as a unicode SMS.
061                 * <a href=developer.nexmo.com/messaging/sms/guides/concatenation-and-encoding>
062                 *  Read more about concatenation and encoding</a>.
063                 *
064                 * @param text The text string.
065                 * @return This builder.
066                 */
067                @Override
068                public Builder text(String text) {
069                        return super.text(text);
070                }
071
072                /**
073                 * (OPTIONAL)
074                 * The encoding type to use for the message. If set to either {@linkplain EncodingType#TEXT} or
075                 * {@linkplain EncodingType#UNICODE}, the specified type will be used. If set to
076                 * {@linkplain EncodingType#AUTO} (the default), the Messages API will automatically set the type based
077                 * on the content of text; i.e. if unicode characters are detected in text, then the message will be
078                 * encoded as unicode, and otherwise as text.
079                 *
080                 * @param encodingType The message encoding type as an enum.
081                 * @return This builder.
082                 *
083                 * @since 8.1.0
084                 */
085                public Builder encodingType(EncodingType encodingType) {
086                        this.encodingType = encodingType;
087                        return this;
088                }
089
090                /**
091                 * (OPTIONAL)
092                 * A string parameter that satisfies regulatory requirements when sending an SMS to specific countries.
093                 *
094                 * @param contentId The content ID as a string.
095                 * @return This builder.
096                 *
097                 * @since 8.1.0
098                 */
099                public Builder contentId(String contentId) {
100                        this.contentId = contentId;
101                        return this;
102                }
103
104                /**
105                 * (OPTIONAL)
106                 * A string parameter that satisfies regulatory requirements when sending an SMS to specific countries.
107                 *
108                 * @param entityId The entity ID as a string.
109                 * @return This builder.
110                 *
111                 * @since 8.1.0
112                 */
113                public Builder entityId(String entityId) {
114                        this.entityId = entityId;
115                        return this;
116                }
117
118                @Override
119                public Builder ttl(int ttl) {
120                        return super.ttl(ttl);
121                }
122
123                @Override
124                public SmsTextRequest build() {
125                        return new SmsTextRequest(this);
126                }
127        }
128}