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.video;
017
018import com.fasterxml.jackson.annotation.JsonCreator;
019import com.fasterxml.jackson.annotation.JsonValue;
020
021/**
022 * Represents the supported BCP-47 language codes for Live Captions.
023 *
024 * @since 8.5.0
025 */
026public enum Language {
027        /**
028         * American English
029         */
030        EN_US,
031
032        /**
033         * Australian English
034         */
035        EN_AU,
036
037        /**
038         * British English
039         */
040        EN_GB,
041
042        /**
043         * Simplified Chinese
044         */
045        ZH_CN,
046
047        /**
048         * French
049         */
050        FR_FR,
051
052        /**
053         * German
054         */
055        DE_DE,
056
057        /**
058         * Hindi
059         */
060        HI_IN,
061
062        /**
063         * Italian
064         */
065        IT_IT,
066
067        /**
068         * Japanese
069         */
070        JA_JP,
071
072        /**
073         * Korean
074         */
075        KO_KR,
076
077        /**
078         * Brazilian Portuguese
079         */
080        PT_BR,
081
082        /**
083         * Thai
084         */
085        TH_TH;
086
087        @JsonCreator
088        public static Language fromString(String name) {
089                if (name == null) return null;
090                try {
091                        return valueOf(name.toUpperCase().replace('-', '_'));
092                }
093                catch (IllegalArgumentException ex) {
094                        return null;
095                }
096        }
097
098        @JsonValue
099        @Override
100        public String toString() {
101                String[] split = name().split("_");
102                assert split.length == 2;
103                return split[0].toLowerCase() + '-' + split[1];
104        }       
105}