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.voice;
017
018import com.fasterxml.jackson.annotation.JsonCreator;
019import com.fasterxml.jackson.annotation.JsonValue;
020
021/**
022 * Describes the status of the call, and also the event in {@link EventWebhook#getStatus()}.
023 */
024public enum CallStatus {
025
026    /**
027     * Indicates that the call has been created.
028     */
029    STARTED,
030
031    /**
032     * The call is ringing.
033     */
034    RINGING,
035
036    /**
037     * The call was answered.
038     */
039    ANSWERED,
040
041    /**
042     * The duration of the ringing phase exceeded the specified ringing timeout duration.
043     */
044    TIMEOUT,
045
046    /**
047     * For an outbound call made programmatically with machine detection enabled,
048     * this indicates a machine / voicemail answered the call.
049     */
050    MACHINE,
051
052    /**
053     * The call has finished.
054     */
055    COMPLETED,
056
057    /**
058     * The outgoing call could not be connected.
059     */
060    FAILED,
061
062    /**
063     * The call was rejected by Vonage before it was connected.
064     */
065    REJECTED,
066
067    /**
068     * The destination is on the line with another caller.
069     */
070    BUSY,
071
072    /**
073     * An outgoing call is cancelled by the originator before being answered.
074     */
075    CANCELLED,
076
077    /**
078     * A leg has been transferred from one conversation to another.
079     */
080    TRANSFER,
081
082    /**
083     * An NCCO {@code input} action has finished.
084     */
085    INPUT,
086
087    /**
088     * For an outbound call made programmatically with machine detection enabled,
089     * this indicates a human answered the call.
090     */
091    HUMAN,
092
093    /**
094     * If the WebSocket connection is terminated from the application side for any reason,
095     * then the disconnected event callback will be sent. If the response contains an NCCO
096     * then this will be processed, if no NCCO is present then normal execution will continue.
097     */
098    DISCONNECTED,
099
100    /**
101     * Either the recipient is unreachable or the recipient declined the call.
102     */
103    UNANSWERED,
104
105    /**
106     * Unknown status or event.
107     */
108    UNKNOWN;
109
110    @JsonValue
111    @Override
112    public String toString() {
113        return name().toLowerCase();
114    }
115
116    @JsonCreator
117    public static CallStatus fromString(String name) {
118        try {
119            return CallStatus.valueOf(name.toUpperCase());
120        }
121        catch (IllegalArgumentException ex) {
122            return UNKNOWN;
123        }
124    }
125}