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.insight; 017 018import com.fasterxml.jackson.annotation.JsonCreator; 019 020import java.util.HashMap; 021import java.util.Map; 022 023public enum InsightStatus { 024 SUCCESS(0), 025 THROTTLED(1), 026 INVALID_PARAMS(3), 027 INVALID_CREDENTIALS(4), 028 INTERNAL_ERROR(5), 029 PARTNER_QUOTA_EXCEEDED(9), 030 UNKNOWN(Integer.MAX_VALUE); 031 032 private int insightStatus; 033 034 private static final Map<Integer, InsightStatus> INSIGHT_STATUS_INDEX = new HashMap<>(); 035 036 static { 037 for (InsightStatus insightStatus : InsightStatus.values()) { 038 INSIGHT_STATUS_INDEX.put(insightStatus.insightStatus, insightStatus); 039 } 040 } 041 042 /** 043 * Look up the {@link InsightStatus} based on the int value. 044 * 045 * @param insightStatus the int value of the insight status. 046 * 047 * @return InsightStatus based on the int value given. 048 */ 049 @JsonCreator 050 public static InsightStatus fromInt(int insightStatus) { 051 InsightStatus foundInsightStatus = INSIGHT_STATUS_INDEX.get(insightStatus); 052 return (foundInsightStatus != null) ? foundInsightStatus : UNKNOWN; 053 } 054 055 InsightStatus(int insightStatus) { 056 this.insightStatus = insightStatus; 057 } 058 059 public int getInsightStatus() { 060 return insightStatus; 061 } 062}