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.messages.viber;
017
018import com.fasterxml.jackson.annotation.JsonProperty;
019import com.vonage.client.messages.MediaMessageRequest;
020import com.vonage.client.messages.MessageType;
021import com.vonage.client.messages.internal.MessagePayload;
022
023/**
024 * @since 7.2.0
025 */
026public final class ViberFileRequest extends ViberRequest implements MediaMessageRequest {
027
028        ViberFileRequest(Builder builder) {
029                super(builder, MessageType.FILE);
030                MessagePayload.validateExtension(media.getName() != null ? media.getName() : media.getUrl().getPath(),
031                                "doc", "docx", "rtf", "dot", "dotx", "odt", "odf", "fodt", "txt", "info",
032                                "pdf", "xps", "pdax", "eps", "xls", "xlsx", "ods", "fods", "csv", "xlsm", "xltx"
033                );
034        }
035
036        @JsonProperty("file")
037        public MessagePayload getFile() {
038                return media;
039        }
040
041        public static Builder builder() {
042                return new Builder();
043        }
044
045        public static final class Builder extends ViberRequest.Builder<ViberFileRequest, Builder> implements MediaMessageRequest.Builder<Builder> {
046                Builder() {}
047
048                /**
049                 * (REQUIRED)
050                 * The URL for the file attachment or the path for the location of the file attachment.
051                 * If name is included, can just be the path.
052                 * If name is not included, must include the filename and extension.
053                 * <p>
054                 * Supported file types are .doc, .docx, .rtf, .dot, .dotx, .odt, .odf, .fodt, .txt, .info, .pdf, .xps,
055                 * .pdax, .eps, .xls, .xlsx, .ods, .fods, .csv, .xlsm, .xltx. Maximum file size is 200MB.
056                 *
057                 * @param url The file URL as a string.
058                 * @return This builder.
059                 */
060                @Override
061                public Builder url(String url) {
062                        return super.url(url);
063                }
064
065                /**
066                 * (OPTIONAL)
067                 * The name and extension of the file.
068                 *
069                 * @param name The filename and extension as a string.
070                 * @return This builder.
071                 */
072                @Override
073                public Builder name(String name) {
074                        return super.name(name);
075                }
076
077                public ViberFileRequest build() {
078                        return new ViberFileRequest(this);
079                }
080        }
081}