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.sms;
017
018import com.fasterxml.jackson.annotation.JsonCreator;
019import com.fasterxml.jackson.annotation.JsonValue;
020import java.util.Arrays;
021import java.util.Map;
022import java.util.function.Function;
023import java.util.stream.Collectors;
024
025/**
026 * Enum representing the error status of an SMS message. See
027 * <a href=https://developer.vonage.com/api-errors/sms>the documentation</a> for more details.
028 */
029public enum MessageStatus {
030    /**
031     * A status of zero does not indicate that Vonage delivered your message. Instead, this
032     * status indicates the absence of an error - i.e. the REST call succeeded.
033     */
034    OK(0),
035
036    /**
037     * You are sending SMS faster than the account limit.
038     */
039    THROTTLED(1),
040
041    /**
042     * Your request is missing one of the required parameters from, to, api_key, api_secret or text.
043     */
044    MISSING_PARAMS(2),
045
046    /**
047     * The value of one or more parameters is invalid.
048     */
049    INVALID_PARAMS(3),
050
051    /**
052     * Your API key and/or secret are incorrect, invalid or disabled.
053     */
054    INVALID_CREDENTIALS(4),
055
056    /**
057     * An error has occurred in the platform whilst processing this message.
058     */
059    INTERNAL_ERROR(5),
060
061    /**
062     * The platform was unable to process this message, for example, an un-recognized number prefix.
063     */
064    INVALID_MESSAGE(6),
065
066    /**
067     * The number you are trying to send messages to is blacklisted and may not receive them.
068     */
069    NUMBER_BARRED(7),
070
071    /**
072     * Your Vonage account has been suspended.
073     */
074    PARTNER_ACCOUNT_BARRED(8),
075
076    /**
077     * You do not have sufficient credit to send the message.
078     */
079    PARTNER_QUOTA_EXCEEDED(9),
080
081    /**
082     * The number of simultaneous connections to the platform exceeds your account allocation.
083     */
084    TOO_MANY_BINDS(10),
085
086    /**
087     * This account is not provisioned for the SMS API.
088     */
089    ACCOUNT_NOT_HTTP(11),
090
091    /**
092     * The message length exceeds the maximum allowed.
093     */
094    MESSAGE_TOO_LONG(12),
095
096    /**
097     * No longer used.
098     */
099    @Deprecated
100    COMMS_FAILURE(13),
101
102    /**
103     * The signature supplied could not be verified.
104     */
105    INVALID_SIGNATURE(14),
106
107    /**
108     * You are using a non-authorized sender ID in the from field.
109     */
110    INVALID_FROM_ADDRESS(15),
111
112    /**
113     * No longer used.
114     */
115    @Deprecated
116    INVALID_TTL(16),
117
118    /**
119     * No longer used.
120     */
121    @Deprecated
122    NUMBER_UNREACHABLE(17),
123
124    /**
125     * No longer used.
126     */
127    @Deprecated
128    TOO_MANY_DESTINATIONS(18),
129
130    /**
131     * No longer used.
132     */
133    @Deprecated
134    FACILITY_NOT_ALLOWED(19),
135
136    /**
137     * No longer used.
138     */
139    @Deprecated
140    INVALID_MESSAGE_CLASS(20),
141
142    /**
143     * The network code supplied was either not recognized, or does not match the country of the destination address.
144     */
145    INVALID_NETWORK_CODE(22),
146
147    /**
148     * The callback URL supplied was either too long or contained illegal characters.
149     */
150    INVALID_CALLBACK(23),
151
152    /**
153     * Your Vonage account is still in demo mode.
154     * While in demo mode you must add target numbers to your whitelisted destination list.
155     */
156    NON_WHITELISTED_DESTINATION(29),
157
158    /**
159     * A signed request may not also present an api_secret.
160     */
161    SIGNATURE_API_SECRET_DISALLOWED(32),
162
163    /**
164     * The number you are trying to send messages to is de-activated and may not receive them.
165     */
166    NUMBER_DEACTIVATED(33),
167
168    /**
169     * Unknown status code.
170     */
171    UNKNOWN(Integer.MAX_VALUE);
172
173    private final int messageStatus;
174
175    private static final Map<Integer, MessageStatus> MESSAGE_STATUS_INDEX =
176        Arrays.stream(MessageStatus.values()).collect(Collectors.toMap(
177            MessageStatus::getMessageStatus, Function.identity()
178        ));
179
180    /**
181     * Look up the MessageStatus based on the int value.
182     *
183     * @param messageStatus the int value of the message status.
184     *
185     * @return MessageStatus based on the int value given.
186     */
187    @JsonCreator
188    public static MessageStatus fromInt(int messageStatus) {
189        return MESSAGE_STATUS_INDEX.getOrDefault(messageStatus, UNKNOWN);
190    }
191
192    MessageStatus(int messageStatus) {
193        this.messageStatus = messageStatus;
194    }
195
196    @JsonValue
197    public int getMessageStatus() {
198        return messageStatus;
199    }
200}