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.insight; 017 018import com.fasterxml.jackson.annotation.JsonCreator; 019import com.fasterxml.jackson.annotation.JsonValue; 020import java.util.Arrays; 021 022public enum InsightStatus { 023 /** 024 * Request accepted for delivery. 025 */ 026 SUCCESS(0), 027 /** 028 * You have made more requests in the last second than are permitted by your account. Please retry. 029 */ 030 THROTTLED(1), 031 /** 032 * Your request is incomplete and missing some mandatory parameters. 033 */ 034 INVALID_PARAMS(3), 035 /** 036 * The api_key or api_secret you supplied is either not valid or has been disabled. 037 */ 038 INVALID_CREDENTIALS(4), 039 /** 040 * The format of the recipient address is not valid. 041 */ 042 INTERNAL_ERROR(5), 043 /** 044 * Your account does not have sufficient credit to process this request. 045 */ 046 PARTNER_QUOTA_EXCEEDED(9), 047 /** 048 * Your request makes use of a facility that is not enabled on your account. 049 */ 050 FACILITY_NOT_ALLOWED(19), 051 /** 052 * Live mobile lookup not returned. Not all return parameters are available. 053 * Possible values are 43, 44 and 45. 054 */ 055 LOOKUP_NOT_RETURNED(43), 056 /** 057 * Request unparseable. 058 */ 059 REQUEST_UNPARSEABLE(999), 060 /** 061 * Undefined or unknown value. 062 */ 063 UNKNOWN(Integer.MAX_VALUE); 064 065 private int statusCode; 066 067 InsightStatus(int statusCode) { 068 this.statusCode = statusCode; 069 } 070 071 /** 072 * Look up the InsightStatus based on the int value. 073 * 074 * @param insightStatus the integer value of the insight status. 075 * @return InsightStatus based on the int value given. 076 */ 077 @JsonCreator 078 public static InsightStatus fromInt(int insightStatus) { 079 if (insightStatus >= 43 && insightStatus <= 45) { 080 InsightStatus lnr = InsightStatus.LOOKUP_NOT_RETURNED; 081 lnr.statusCode = insightStatus; 082 return lnr; 083 } 084 return Arrays.stream(InsightStatus.values()) 085 .filter(status -> status.statusCode == insightStatus) 086 .findAny().orElseGet(() -> { 087 InsightStatus wildcard = UNKNOWN; 088 wildcard.statusCode = insightStatus; 089 return wildcard; 090 }); 091 } 092 093 /** 094 * @return The status code used to create this enum. 095 */ 096 @JsonValue 097 public int getInsightStatus() { 098 return statusCode; 099 } 100}