001/* 002 * Copyright (c) 2011-2017 Nexmo Inc 003 * 004 * Permission is hereby granted, free of charge, to any person obtaining a copy 005 * of this software and associated documentation files (the "Software"), to deal 006 * in the Software without restriction, including without limitation the rights 007 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 008 * copies of the Software, and to permit persons to whom the Software is 009 * furnished to do so, subject to the following conditions: 010 * 011 * The above copyright notice and this permission notice shall be included in 012 * all copies or substantial portions of the Software. 013 * 014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 015 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 016 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 017 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 018 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 019 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 020 * THE SOFTWARE. 021 */ 022package com.nexmo.client.sms; 023 024import com.fasterxml.jackson.annotation.JsonCreator; 025 026import java.util.HashMap; 027import java.util.Map; 028 029public enum MessageStatus { 030 OK(0), 031 THROTTLED(1), 032 MISSING_PARAMS(2), 033 INVALID_PARAMS(3), 034 INVALID_CREDENTIALS(4), 035 INTERNAL_ERROR(5), 036 INVALID_MESSAGE(6), 037 NUMBER_BARRED(7), 038 PARTNER_ACCOUNT_BARRED(8), 039 PARTNER_QUOTA_EXCEEDED(9), 040 TOO_MANY_BINDS(10), 041 ACCOUNT_NOT_HTTP(11), 042 MESSAGE_TOO_LONG(12), 043 COMMS_FAILURE(13), 044 INVALID_SIGNATURE(14), 045 INVALID_FROM_ADDRESS(15), 046 INVALID_TTL(16), 047 NUMBER_UNREACHABLE(17), 048 TOO_MANY_DESTINATIONS(18), 049 FACILITY_NOT_ALLOWED(19), INVALID_MESSAGE_CLASS(20), UNKNOWN(Integer.MAX_VALUE); 050 051 private int messageStatus; 052 053 private static final Map<Integer, MessageStatus> MESSAGE_STATUS_INDEX = new HashMap<>(); 054 055 static { 056 for (MessageStatus messageStatus : MessageStatus.values()) { 057 MESSAGE_STATUS_INDEX.put(messageStatus.messageStatus, messageStatus); 058 } 059 } 060 061 /** 062 * Look up the {@link MessageStatus} based on the int value. 063 * 064 * @param messageStatus the int value of the message status. 065 * 066 * @return MessageStatus based on the int value given. 067 */ 068 @JsonCreator 069 public static MessageStatus fromInt(int messageStatus) { 070 MessageStatus foundStatus = MESSAGE_STATUS_INDEX.get(messageStatus); 071 return (foundStatus != null) ? foundStatus : UNKNOWN; 072 } 073 074 MessageStatus(int messageStatus) { 075 this.messageStatus = messageStatus; 076 } 077 078 public int getMessageStatus() { 079 return this.messageStatus; 080 } 081}