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 java.net.URI;
020
021/**
022 * Defines the captioning properties used in {@link VideoClient#startCaptions(CaptionsRequest)}.
023 *
024 * @since 8.5.0
025 */
026public final class CaptionsRequest extends AbstractSessionTokenRequest {
027    private Language languageCode;
028    private Integer maxDuration;
029    private Boolean partialCaptions;
030    private URI statusCallbackUrl;
031
032    private CaptionsRequest() {}
033
034    private CaptionsRequest(Builder builder) {
035        super(builder);
036        statusCallbackUrl = builder.statusCallbackUrl;
037        languageCode = builder.languageCode;
038        partialCaptions = builder.partialCaptions;
039        if ((maxDuration = builder.maxDuration) != null && (maxDuration < 300 || maxDuration > 14400)) {
040            throw new IllegalArgumentException("Max duration must be between 300 and 14400 seconds.");
041        }
042    }
043
044    /**
045     * A publicly reachable URL controlled by the customer and capable of generating the content to
046     * be rendered without user intervention.
047     *
048     * @return The status callback URL, or {@code null} if not set.
049     */
050    @JsonProperty("statusCallbackUrl")
051    public URI getStatusCallbackUrl() {
052        return statusCallbackUrl;
053    }
054
055    /**
056     * Spoken language used on this call in BCP-47 format.
057     *
058     * @return The language code as an enum.
059     */
060    @JsonProperty("languageCode")
061    public Language getLanguageCode() {
062        return languageCode;
063    }
064
065    /**
066     * The maximum duration for the audio captioning, in seconds.
067     *
068     * @return The maximum captioning duration as an integer.
069     */
070    @JsonProperty("maxDuration")
071    public Integer getMaxDuration() {
072        return maxDuration;
073    }
074
075    /**
076     * Whether faster captioning is enabled at the cost of some degree of inaccuracies.
077     *
078     * @return {@code true} if the partial captions setting is enabled.
079     */
080    @JsonProperty("partialCaptions")
081    public Boolean partialCaptions() {
082        return partialCaptions;
083    }
084
085    /**
086     * Entry point for constructing an instance of this class.
087     *
088     * @return A new Builder.
089     */
090    public static Builder builder() {
091        return new Builder();
092    }
093
094    /**
095     * Builder for defining the fields in a StartCaptionsRequest object.
096     */
097    public static final class Builder extends AbstractSessionTokenRequest.Builder<CaptionsRequest, Builder> {
098        private URI statusCallbackUrl;
099        private Language languageCode;
100        private Integer maxDuration;
101        private Boolean partialCaptions;
102
103        private Builder() {
104        }
105
106        /**
107         * BCP-47 code for a spoken language used on this call. The default value is {@linkplain Language#EN_US}.
108         *
109         * @param languageCode The BCP-47 language code as an enum.
110         *
111         * @return This Builder with the languageCode property setting.
112         */
113        public Builder languageCode(Language languageCode) {
114            this.languageCode = languageCode;
115            return this;
116        }
117
118        /**
119         * A publicly reachable URL controlled by the customer and capable of generating the content to
120         * be rendered without user intervention. The minimum length of the URL is 15 characters and the
121         * maximum length is 2048 characters.
122         *
123         * @param statusCallbackUrl The status callback URL as a string.
124         *
125         * @return This Builder with the statusCallbackUrl property setting.
126         */
127        public Builder statusCallbackUrl(String statusCallbackUrl) {
128            if (statusCallbackUrl == null || statusCallbackUrl.length() < 15 || statusCallbackUrl.length() > 2048) {
129                throw new IllegalArgumentException("Status callback URL must be between 15 and 2048 characters.");
130            }
131            this.statusCallbackUrl = URI.create(statusCallbackUrl);
132            return this;
133        }
134
135        /**
136         * The maximum duration for the audio captioning, in seconds.
137         * The default value is 14,400 seconds (4 hours), the maximum duration allowed.
138         * The minimum value is 300 seconds.
139         *
140         * @param maxDuration The maximum captions duration in seconds.
141         *
142         * @return This Builder with the maxDuration property setting.
143         */
144        public Builder maxDuration(int maxDuration) {
145            this.maxDuration = maxDuration;
146            return this;
147        }
148
149        /**
150         * Whether to enable this to faster captioning at the cost of some degree of inaccuracies.
151         * The default value is {@code true}.
152         *
153         * @param partialCaptions Whether to enable faster captions.
154         *
155         * @return This Builder with the partialCaptions property setting.
156         */
157        public Builder partialCaptions(boolean partialCaptions) {
158            this.partialCaptions = partialCaptions;
159            return this;
160        }
161
162        /**
163         * Builds the StartCaptionsRequest object.
164         *
165         * @return The StartCaptionsRequest object with this builder's settings.
166         */
167        @Override
168        public CaptionsRequest build() {
169            return new CaptionsRequest(this);
170        }
171    }
172}