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.numbers;
017
018import com.fasterxml.jackson.annotation.JsonCreator;
019import com.fasterxml.jackson.annotation.JsonValue;
020
021/**
022 * Enumeration representing the type of number.
023 */
024public enum Type {
025    LANDLINE,
026    MOBILE_LVN,
027    LANDLINE_TOLL_FREE,
028    UNKNOWN;
029
030    /**
031     * Serialized name.
032     *
033     * @return The string value.
034     * @deprecated Use {@link #toString()}
035     */
036    @Deprecated
037    public String getType() {
038        return toString();
039    }
040
041    @JsonValue
042    @Override
043    public String toString() {
044        return name().toLowerCase().replace('_', '-');
045    }
046
047    /**
048     * Creates an instance of this enum from its serialized string representation.
049     *
050     * @param type The number type as a string.
051     * @return An enum representation of the number type.
052     */
053    @JsonCreator
054    public static Type fromString(String type) {
055        if (type == null) return null;
056        try {
057            return Type.valueOf(type.toUpperCase().replace('-', '_'));
058        }
059        catch (IllegalArgumentException ex) {
060            return UNKNOWN;
061        }
062    }
063}