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.verify;
017
018import com.fasterxml.jackson.annotation.JsonProperty;
019import com.vonage.client.JsonableBaseObject;
020import com.vonage.client.VonageResponseParseException;
021
022public class VerifyResponse extends JsonableBaseObject {
023    private VerifyStatus status;
024    private String requestId, errorText, network;
025
026    private VerifyResponse() {
027    }
028
029    public VerifyResponse(VerifyStatus status) {
030        this.status = status;
031    }
032
033    /**
034     * @return The unique ID of the Verify request. You need this {@code request_id} for the Verify check.
035     * Note that this may not be present when {@link #getNetwork()} returns a non-null / non-empty value.
036     */
037    @JsonProperty("request_id")
038    public String getRequestId() {
039        return requestId;
040    }
041
042    /**
043     * @return The outcome of the request; {@code 0} (i.e. {@link VerifyStatus#OK}) indicates success.
044     */
045    @JsonProperty("status")
046    public VerifyStatus getStatus() {
047        return status;
048    }
049
050    /**
051     * @return If status is non-zero, this explains the error encountered.
052     */
053    @JsonProperty("error_text")
054    public String getErrorText() {
055        return errorText;
056    }
057
058    /**
059     * @return The network ID, if {@link #getStatus()} returns {@link VerifyStatus#NUMBER_BARRED}.
060     *
061     * @since 7.1.0
062     */
063    @JsonProperty("network")
064    public String getNetwork() {
065        return network;
066    }
067
068    public static VerifyResponse fromJson(String json) {
069        VerifyResponse response = new VerifyResponse();
070        response.updateFromJson(json);
071        if (response.status == null) {
072            throw new VonageResponseParseException("Response status is missing.");
073        }
074        return response;
075    }
076}