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.verify; 017 018import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 019 020import java.util.HashMap; 021import java.util.Map; 022 023@JsonDeserialize(using = VerifyStatusDeserializer.class) 024public enum VerifyStatus { 025 OK(0), 026 THROTTLED(1), 027 MISSING_PARAMS(2), 028 INVALID_PARAMS(3), 029 INVALID_CREDENTIALS(4), 030 INTERNAL_ERROR(5), 031 INVALID_REQUEST(6), 032 NUMBER_BARRED(7), 033 PARTNER_ACCOUNT_BARRED(8), 034 PARTNER_QUOTA_EXCEEDED(9), 035 ALREADY_REQUESTED(10), 036 UNSUPPORTED_NETWORK(15), 037 INVALID_CODE(16), 038 WRONG_CODE_THROTTLED(17), 039 TOO_MANY_DESTINATIONS(18), 040 NO_RESPONSE(101), COMMS_FAILURE(-1), UNKNOWN(Integer.MAX_VALUE); 041 042 private int verifyStatus; 043 044 private static final Map<Integer, VerifyStatus> VERIFY_STATUS_INDEX = new HashMap<>(); 045 046 static { 047 for (VerifyStatus verifyStatus : VerifyStatus.values()) { 048 VERIFY_STATUS_INDEX.put(verifyStatus.verifyStatus, verifyStatus); 049 } 050 } 051 052 /** 053 * Look up the {@link VerifyStatus} based on the int value. 054 * 055 * @param verifyStatus the int value of the verify status. 056 * 057 * @return VerifyStatus based on the int value given. 058 */ 059 public static VerifyStatus fromInt(int verifyStatus) { 060 VerifyStatus foundVerifyStatus = VERIFY_STATUS_INDEX.get(verifyStatus); 061 return (foundVerifyStatus != null) ? foundVerifyStatus : UNKNOWN; 062 } 063 064 VerifyStatus(int verifyStatus) { 065 this.verifyStatus = verifyStatus; 066 } 067 068 public int getVerifyStatus() { 069 return this.verifyStatus; 070 } 071 072 public boolean isTemporaryError() { 073 return this == THROTTLED || this == INTERNAL_ERROR; 074 } 075}