001/*
002 *   Copyright 2023 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.messages.viber;
017
018import com.fasterxml.jackson.annotation.JsonInclude;
019import com.fasterxml.jackson.annotation.JsonProperty;
020import com.vonage.client.messages.internal.MessagePayload;
021import com.vonage.client.messages.MessageType;
022
023@JsonInclude(value = JsonInclude.Include.NON_NULL)
024public final class ViberImageRequest extends ViberRequest {
025        final MessagePayload image;
026
027        ViberImageRequest(Builder builder) {
028                super(builder, MessageType.IMAGE);
029                image = new MessagePayload(builder.url);
030                image.validateUrlExtension("jpg", "jpeg", "png");
031        }
032
033        @JsonProperty("image")
034        public MessagePayload getImage() {
035                return image;
036        }
037
038        public static Builder builder() {
039                return new Builder();
040        }
041
042        public static final class Builder extends ViberRequest.Builder<ViberImageRequest, Builder> {
043                String url;
044
045                Builder() {}
046
047                /**
048                 * (REQUIRED)
049                 * Sets the URL of the image attachment. Supports only
050                 * {@code .jpg}, {@code .jpeg} and {@code .png}
051                 * file extensions.
052                 *
053                 * @param url The URL as a string.
054                 * @return This builder.
055                 */
056                public Builder url(String url) {
057                        this.url = url;
058                        return this;
059                }
060
061                @Override
062                public Builder actionUrl(String actionUrl) {
063                        return super.actionUrl(actionUrl);
064                }
065
066                @Override
067                public Builder actionText(String actionText) {
068                        return super.actionText(actionText);
069                }
070
071                @Override
072                public ViberImageRequest build() {
073                        return new ViberImageRequest(this);
074                }
075        }
076}