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.List;
021
022public final class WhatsappTemplateRequest extends WhatsappRequest {
023        final Template template;
024        final Whatsapp whatsapp;
025
026        WhatsappTemplateRequest(Builder builder) {
027                super(builder, MessageType.TEMPLATE);
028                template = new Template(builder.name, builder.parameters);
029                whatsapp = new Whatsapp(builder.policy, builder.locale);
030        }
031
032        @JsonProperty("template")
033        public Template getTemplate() {
034                return template;
035        }
036
037        @JsonProperty("whatsapp")
038        public Whatsapp getWhatsapp() {
039                return whatsapp;
040        }
041
042        public static Builder builder() {
043                return new Builder();
044        }
045
046        public static final class Builder extends WhatsappRequest.Builder<WhatsappTemplateRequest, Builder> {
047                String name;
048                List<String> parameters;
049                Locale locale = Locale.ENGLISH;
050                Policy policy;
051
052                Builder() {}
053
054                /**
055                 * (REQUIRED)
056                 * The name of the template. For WhatsApp use your WhatsApp namespace (available via Facebook Business Manager),
057                 * followed by a colon : and the name of the template to use.
058                 *
059                 * @param name The template name.
060                 * @return This builder.
061                 */
062                public Builder name(String name) {
063                        this.name = name;
064                        return this;
065                }
066
067                /**
068                 * (OPTIONAL)
069                 * The parameters are an array of strings, with the first being substituted for {{1}} in the template,
070                 * the second being {{2}} etc. You can find the full list of supported parameters on WhatsApp's
071                 * <a href=https://developers.facebook.com/docs/whatsapp/on-premises/reference/messages#message-templates>
072                 * messages parameters documentation</a>.
073                 *
074                 * @param parameters The list of template parameters.
075                 * @return This builder.
076                 */
077                public Builder parameters(List<String> parameters) {
078                        this.parameters = parameters;
079                        return this;
080                }
081
082                /**
083                 * (OPTIONAL)
084                 * Policy for resolving what language template to use.
085                 *
086                 * @param policy The policy field.
087                 * @return This builder.
088                 */
089                public Builder policy(Policy policy) {
090                        this.policy = policy;
091                        return this;
092                }
093
094                /**
095                 * (REQUIRED)
096                 * The BCP 47 language of the template. Defaults to {@linkplain Locale#ENGLISH} if not set.
097                 * 
098                 * @param locale The {@link Locale}.
099                 * @return This builder.
100                 */
101                public Builder locale(Locale locale) {
102                        this.locale = locale;
103                        return this;
104                }
105
106                @Override
107                public WhatsappTemplateRequest build() {
108                        return new WhatsappTemplateRequest(this);
109                }
110        }
111}