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.whatsapp;
017
018import com.fasterxml.jackson.annotation.JsonProperty;
019import com.vonage.client.messages.MessageType;
020import java.util.Objects;
021import java.util.UUID;
022
023/**
024 * {@link com.vonage.client.messages.Channel#WHATSAPP}, {@link MessageType#REACTION} request.
025 *
026 * @since 8.11.0
027 */
028public final class WhatsappReactionRequest extends WhatsappRequest {
029        final Reaction reaction;
030
031        WhatsappReactionRequest(Builder builder) {
032                super(builder, MessageType.REACTION);
033                reaction = Objects.requireNonNull(builder.reaction, "Reaction is required.");
034                if (getContext() == null) {
035                        throw new IllegalStateException("Context message ID is required.");
036                }
037        }
038
039        @JsonProperty("reaction")
040        public Reaction getReaction() {
041                return reaction;
042        }
043
044        public static Builder builder() {
045                return new Builder();
046        }
047
048        public static final class Builder extends WhatsappRequest.Builder<WhatsappReactionRequest, Builder> {
049                private Reaction reaction;
050
051                Builder() {}
052
053                /**
054                 * (REQUIRED unless {@linkplain #unreact()} is called)
055                 * Set the reaction to the message. This must be a single emoji character in UTF-8 encoding.
056                 *
057                 * @param emoji The emoji character to use as a string.
058                 * @return This builder.
059                 */
060                public Builder reaction(String emoji) {
061                        reaction = new Reaction(emoji);
062                        return this;
063                }
064
065                /**
066                 * (REQUIRED unless {@linkplain #reaction(String)} is called)
067                 * Unreact to the message.
068                 *
069                 * @return This builder.
070                 */
071                public Builder unreact() {
072                        reaction = new Reaction();
073                        return this;
074                }
075
076                @Override
077                public WhatsappReactionRequest build() {
078                        return new WhatsappReactionRequest(this);
079                }
080        }
081}