001/*
002 *   Copyright 2020 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;
019
020import java.util.HashMap;
021import java.util.Map;
022
023public enum MessageStatus {
024    OK(0),
025    THROTTLED(1),
026    MISSING_PARAMS(2),
027    INVALID_PARAMS(3),
028    INVALID_CREDENTIALS(4),
029    INTERNAL_ERROR(5),
030    INVALID_MESSAGE(6),
031    NUMBER_BARRED(7),
032    PARTNER_ACCOUNT_BARRED(8),
033    PARTNER_QUOTA_EXCEEDED(9),
034    TOO_MANY_BINDS(10),
035    ACCOUNT_NOT_HTTP(11),
036    MESSAGE_TOO_LONG(12),
037    COMMS_FAILURE(13),
038    INVALID_SIGNATURE(14),
039    INVALID_FROM_ADDRESS(15),
040    INVALID_TTL(16),
041    NUMBER_UNREACHABLE(17),
042    TOO_MANY_DESTINATIONS(18),
043    FACILITY_NOT_ALLOWED(19), INVALID_MESSAGE_CLASS(20), UNKNOWN(Integer.MAX_VALUE);
044
045    private int messageStatus;
046
047    private static final Map<Integer, MessageStatus> MESSAGE_STATUS_INDEX = new HashMap<>();
048
049    static {
050        for (MessageStatus messageStatus : MessageStatus.values()) {
051            MESSAGE_STATUS_INDEX.put(messageStatus.messageStatus, messageStatus);
052        }
053    }
054
055    /**
056     * Look up the {@link MessageStatus} based on the int value.
057     *
058     * @param messageStatus the int value of the message status.
059     *
060     * @return MessageStatus based on the int value given.
061     */
062    @JsonCreator
063    public static MessageStatus fromInt(int messageStatus) {
064        MessageStatus foundStatus = MESSAGE_STATUS_INDEX.get(messageStatus);
065        return (foundStatus != null) ? foundStatus : UNKNOWN;
066    }
067
068    MessageStatus(int messageStatus) {
069        this.messageStatus = messageStatus;
070    }
071
072    public int getMessageStatus() {
073        return this.messageStatus;
074    }
075}