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.numbers;
017
018import com.fasterxml.jackson.annotation.JsonCreator;
019import com.fasterxml.jackson.annotation.JsonValue;
020
021import java.util.HashMap;
022import java.util.Map;
023
024/**
025 * Enumeration representing the type of number.
026 */
027public enum Type {
028    LANDLINE("landline"),
029    MOBILE_LVN("mobile-lvn"),
030    LANDLINE_TOLL_FREE("landline-toll-free"),
031    UNKNOWN("unknown");
032
033    private static final Map<String, Type> TYPE_INDEX = new HashMap<>();
034
035    static {
036        for (Type type : Type.values()) {
037            TYPE_INDEX.put(type.type, type);
038        }
039    }
040
041    private String type;
042
043    Type(String type) {
044        this.type = type;
045    }
046
047    @JsonValue
048    public String getType() {
049        return type;
050    }
051
052    @JsonCreator
053    public static Type fromString(String type) {
054        Type foundType = TYPE_INDEX.get(type);
055        return (foundType != null) ? foundType : UNKNOWN;
056    }
057}