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.ncco;
017
018import com.fasterxml.jackson.annotation.JsonProperty;
019import com.vonage.client.JsonableBaseObject;
020import com.vonage.client.voice.EndpointType;
021import java.net.URI;
022import java.util.Map;
023
024/**
025 * Represents a web socket endpoint used in a {@link ConnectAction}. See
026 * <a href=https://developer.vonage.com/voice/voice-api/ncco-reference#websocket-endpoint>the documentation</a>
027 * for an example.
028 */
029public class WebSocketEndpoint extends JsonableBaseObject implements Endpoint {
030    private final URI uri;
031    private final String contentType;
032    private final Map<String, ?> headers;
033
034    private WebSocketEndpoint(Builder builder) {
035        uri = builder.uri;
036        contentType = builder.contentType;
037        headers = builder.headers;
038    }
039
040    @JsonProperty("uri")
041    public URI getUri() {
042        return uri;
043    }
044
045    @Override
046    public String getType() {
047        return EndpointType.WEBSOCKET.toString();
048    }
049
050    @JsonProperty("content-type")
051    public String getContentType() {
052        return contentType;
053    }
054
055    @JsonProperty("headers")
056    public Map<String, ?> getHeaders() {
057        return headers;
058    }
059
060    public static Builder builder(String uri, String contentType) {
061        return new Builder(uri, contentType);
062    }
063
064    public static class Builder {
065        private URI uri;
066        private String contentType;
067        private Map<String, ?> headers;
068
069        Builder(String uri, String contentType) {
070            this.uri = URI.create(uri);
071            this.contentType = contentType;
072        }
073
074        public Builder uri(URI uri) {
075            this.uri = uri;
076            return this;
077        }
078
079        public Builder uri(String uri) {
080            return uri(URI.create(uri));
081        }
082
083        public Builder contentType(String contentType) {
084            this.contentType = contentType;
085            return this;
086        }
087
088        public Builder headers(Map<String, ?> headers) {
089            this.headers = headers;
090            return this;
091        }
092
093        public WebSocketEndpoint build() {
094            return new WebSocketEndpoint(this);
095        }
096    }
097}