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.account; 017 018import com.fasterxml.jackson.annotation.JsonCreator; 019import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 020import com.fasterxml.jackson.annotation.JsonProperty; 021import com.fasterxml.jackson.annotation.JsonValue; 022 023import java.math.BigDecimal; 024import java.util.HashMap; 025import java.util.Map; 026 027@JsonIgnoreProperties(ignoreUnknown = true) 028public class Network { 029 private Type type; 030 private BigDecimal price; 031 private String currency; 032 private String mcc; 033 private String mnc; 034 private String code; 035 private String name; 036 037 public Type getType() { 038 return type; 039 } 040 041 public BigDecimal getPrice() { 042 return price; 043 } 044 045 public String getCurrency() { 046 return currency; 047 } 048 049 public String getMcc() { 050 return mcc; 051 } 052 053 public String getMnc() { 054 return mnc; 055 } 056 057 @JsonProperty("networkCode") 058 public String getCode() { 059 return code; 060 } 061 062 @JsonProperty("networkName") 063 public String getName() { 064 return name; 065 } 066 067 enum Type { 068 MOBILE, LANDLINE, PAGER, LANDLINE_TOLLFREE, UNKNOWN; 069 070 private static final Map<String, Type> typesIndex = new HashMap<>(); 071 072 static { 073 for (Type type : Type.values()) { 074 typesIndex.put(type.toString(), type); 075 } 076 } 077 078 @Override 079 @JsonValue 080 public String toString() { 081 return name().toLowerCase(); 082 } 083 084 @JsonCreator 085 public static Type fromString(String type) { 086 Type foundType = typesIndex.get(type); 087 return (foundType != null) ? foundType : Type.UNKNOWN; 088 } 089 } 090}