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.JsonProperty;
019import com.vonage.client.Jsonable;
020import com.vonage.client.JsonableBaseObject;
021import com.vonage.client.VonageResponseParseException;
022import java.io.IOException;
023import java.net.URI;
024import java.util.UUID;
025
026public class CreateSessionResponse extends JsonableBaseObject {
027        private String sessionId, createDt;
028        private UUID applicationId;
029        private URI mediaServerUrl;
030
031        protected CreateSessionResponse() {
032        }
033
034        /**
035         * @return The session ID.
036         */
037        @JsonProperty("session_id")
038        public String getSessionId() {
039                return sessionId;
040        }
041
042        /**
043         * @return The application ID.
044         */
045        @JsonProperty("application_id")
046        public UUID getApplicationId() {
047                return applicationId;
048        }
049
050        /**
051         * @return The creation date.
052         */
053        @JsonProperty("create_dt")
054        public String getCreateDt() {
055                return createDt;
056        }
057
058        /**
059         * @return The URL of the Media Router used by the session.
060         */
061        @JsonProperty("media_server_url")
062        public URI getMediaServerUrl() {
063                return mediaServerUrl;
064        }
065
066        /**
067         * Creates an instance of this class from a JSON payload.
068         *
069         * @param json The JSON string to parse.
070         * @return An instance of this class with the fields populated, if present.
071         */
072        public static CreateSessionResponse fromJson(String json) {
073                try {
074                        CreateSessionResponse[] array = Jsonable.createDefaultObjectMapper()
075                                        .readValue(json, CreateSessionResponse[].class);
076                        if (array == null || array.length == 0) {
077                                return new CreateSessionResponse();
078                        }
079                        return array[0];
080                }
081                catch (IOException ex) {
082                        throw new VonageResponseParseException("Failed to produce CreateSessionResponse from json.", ex);
083                }
084        }
085}