001// Generated by delombok at Tue Dec 10 13:42:03 UTC 2024
002/*
003 * Copyright (c) 2010-2024 Mark Allen, Norbert Bartels.
004 *
005 * Permission is hereby granted, free of charge, to any person obtaining a copy
006 * of this software and associated documentation files (the "Software"), to deal
007 * in the Software without restriction, including without limitation the rights
008 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
009 * copies of the Software, and to permit persons to whom the Software is
010 * furnished to do so, subject to the following conditions:
011 *
012 * The above copyright notice and this permission notice shall be included in
013 * all copies or substantial portions of the Software.
014 *
015 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
016 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
017 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
018 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
019 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
020 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
021 * THE SOFTWARE.
022 */
023package com.restfb.types.webhook.messaging;
024
025import java.util.ArrayList;
026import java.util.Date;
027import java.util.List;
028import com.restfb.Facebook;
029import com.restfb.JsonMapper;
030import com.restfb.json.JsonObject;
031import com.restfb.json.JsonValue;
032
033public class MessagingItem {
034  @Facebook
035  private MessagingParticipant sender;
036  @Facebook
037  private MessagingParticipant recipient;
038  @Facebook("timestamp")
039  private Long rawTimestamp;
040  private Date timestamp;
041  @Facebook
042  private DeliveryItem delivery;
043  @Facebook
044  private ReadItem read;
045  @Facebook
046  private MessageItem message;
047  @Facebook("message_edit")
048  private MessageEditItem messageEdit;
049  @Facebook
050  private PostbackItem postback;
051  @Facebook
052  private OptinItem optin;
053  @Facebook("account_linking")
054  private AccountLinkingItem accountLinking;
055  @Facebook("checkout_update")
056  private CheckoutUpdateItem checkoutUpdate;
057  @Facebook
058  private PaymentItem payment;
059  @Facebook
060  private ReferralItem referral;
061  @Facebook("policy-enforcement")
062  private PolicyEnforcementItem policyEnforcement;
063  @Facebook("pass_thread_control")
064  private PassThreadControlItem passThreadControl;
065  @Facebook("take_thread_control")
066  private TakeThreadControlItem takeThreadControl;
067  @Facebook("request_thread_control")
068  private RequestThreadControlItem requestThreadControl;
069  private AppRoles appRoles;
070  @Facebook("prior_message")
071  private PriorMessage priorMessage;
072  @Facebook
073  private MessageReaction reaction;
074  @Facebook("app_roles")
075  private JsonObject rawAppRoles;
076
077  /**
078   * generic access to the inner item.
079   * 
080   * depending on the inner elements the corresponding element is returned. So you can get an {@link OptinItem},
081   * {@link PostbackItem}, {@link DeliveryItem}, {@link AccountLinkingItem} or {@link MessageItem}
082   * 
083   * @return the inner item.
084   */
085  public InnerMessagingItem getItem() {
086    if (optin != null) {
087      return optin;
088    }
089    if (postback != null) {
090      return postback;
091    }
092    if (delivery != null) {
093      return delivery;
094    }
095    if (read != null) {
096      return read;
097    }
098    if (accountLinking != null) {
099      return accountLinking;
100    }
101    if (message != null) {
102      return message;
103    }
104    if (checkoutUpdate != null) {
105      return checkoutUpdate;
106    }
107    if (payment != null) {
108      return payment;
109    }
110    if (referral != null) {
111      return referral;
112    }
113    if (policyEnforcement != null) {
114      return policyEnforcement;
115    }
116    if (passThreadControl != null) {
117      return passThreadControl;
118    }
119    if (takeThreadControl != null) {
120      return takeThreadControl;
121    }
122    if (requestThreadControl != null) {
123      return requestThreadControl;
124    }
125    if (appRoles != null) {
126      return appRoles;
127    }
128    if (reaction != null) {
129      return reaction;
130    }
131    return null;
132  }
133
134  public boolean isDelivery() {
135    return getItem() instanceof DeliveryItem;
136  }
137
138  public boolean isRead() {
139    return getItem() instanceof ReadItem;
140  }
141
142  public boolean isMessage() {
143    return getItem() instanceof MessageItem;
144  }
145
146  public boolean isPostback() {
147    return getItem() instanceof PostbackItem;
148  }
149
150  public boolean isOptin() {
151    return getItem() instanceof OptinItem;
152  }
153
154  public boolean isAccountLinking() {
155    return getItem() instanceof AccountLinkingItem;
156  }
157
158  public boolean isCheckoutUpdate() {
159    return getItem() instanceof CheckoutUpdateItem;
160  }
161
162  public boolean isPayment() {
163    return getItem() instanceof PaymentItem;
164  }
165
166  public boolean isReferral() {
167    return getItem() instanceof ReferralItem;
168  }
169
170  public boolean isPolicyEnforcement() {
171    return getItem() instanceof PolicyEnforcementItem;
172  }
173
174  public boolean isPassThreadControl() {
175    return getItem() instanceof PassThreadControlItem;
176  }
177
178  public boolean isTakeThreadControl() {
179    return getItem() instanceof TakeThreadControlItem;
180  }
181
182  public boolean isRequestThreadControl() {
183    return getItem() instanceof RequestThreadControlItem;
184  }
185
186  public boolean isAppRoles() {
187    return getItem() instanceof AppRoles;
188  }
189
190  public boolean hasPriorMessage() {
191    return priorMessage != null;
192  }
193
194  public boolean isReaction() {
195    return getItem() instanceof MessageReaction;
196  }
197
198  @JsonMapper.JsonMappingCompleted
199  private void convertDate() {
200    if (rawTimestamp != null) {
201      timestamp = new Date(rawTimestamp);
202    }
203  }
204
205  @JsonMapper.JsonMappingCompleted
206  private void convertAppRoles() {
207    if (rawAppRoles != null) {
208      AppRoles appRoles = new AppRoles();
209      for (String appId : rawAppRoles.names()) {
210        List<JsonValue> rawRoles = rawAppRoles.get(appId).asArray().values();
211        List<String> roles = new ArrayList<>();
212        for (JsonValue rawValue : rawRoles) {
213          roles.add(rawValue.asString());
214        }
215        appRoles.addRoles(appId, roles);
216      }
217      this.appRoles = appRoles;
218    }
219  }
220
221  @java.lang.Override
222  @java.lang.SuppressWarnings("all")
223  public java.lang.String toString() {
224    return "MessagingItem(sender=" + this.getSender() + ", recipient=" + this.getRecipient() + ", rawTimestamp=" + this.rawTimestamp + ", timestamp=" + this.getTimestamp() + ", delivery=" + this.getDelivery() + ", read=" + this.getRead() + ", message=" + this.getMessage() + ", messageEdit=" + this.getMessageEdit() + ", postback=" + this.getPostback() + ", optin=" + this.getOptin() + ", accountLinking=" + this.getAccountLinking() + ", checkoutUpdate=" + this.getCheckoutUpdate() + ", payment=" + this.getPayment() + ", referral=" + this.getReferral() + ", policyEnforcement=" + this.getPolicyEnforcement() + ", passThreadControl=" + this.getPassThreadControl() + ", takeThreadControl=" + this.getTakeThreadControl() + ", requestThreadControl=" + this.getRequestThreadControl() + ", appRoles=" + this.getAppRoles() + ", priorMessage=" + this.getPriorMessage() + ", reaction=" + this.getReaction() + ", rawAppRoles=" + this.rawAppRoles + ")";
225  }
226
227  @java.lang.SuppressWarnings("all")
228  public MessagingParticipant getSender() {
229    return this.sender;
230  }
231
232  @java.lang.SuppressWarnings("all")
233  public void setSender(final MessagingParticipant sender) {
234    this.sender = sender;
235  }
236
237  @java.lang.SuppressWarnings("all")
238  public MessagingParticipant getRecipient() {
239    return this.recipient;
240  }
241
242  @java.lang.SuppressWarnings("all")
243  public void setRecipient(final MessagingParticipant recipient) {
244    this.recipient = recipient;
245  }
246
247  @java.lang.SuppressWarnings("all")
248  public Date getTimestamp() {
249    return this.timestamp;
250  }
251
252  @java.lang.SuppressWarnings("all")
253  public void setTimestamp(final Date timestamp) {
254    this.timestamp = timestamp;
255  }
256
257  @java.lang.SuppressWarnings("all")
258  public DeliveryItem getDelivery() {
259    return this.delivery;
260  }
261
262  @java.lang.SuppressWarnings("all")
263  public void setDelivery(final DeliveryItem delivery) {
264    this.delivery = delivery;
265  }
266
267  @java.lang.SuppressWarnings("all")
268  public ReadItem getRead() {
269    return this.read;
270  }
271
272  @java.lang.SuppressWarnings("all")
273  public void setRead(final ReadItem read) {
274    this.read = read;
275  }
276
277  @java.lang.SuppressWarnings("all")
278  public MessageItem getMessage() {
279    return this.message;
280  }
281
282  @java.lang.SuppressWarnings("all")
283  public void setMessage(final MessageItem message) {
284    this.message = message;
285  }
286
287  @java.lang.SuppressWarnings("all")
288  public MessageEditItem getMessageEdit() {
289    return this.messageEdit;
290  }
291
292  @java.lang.SuppressWarnings("all")
293  public void setMessageEdit(final MessageEditItem messageEdit) {
294    this.messageEdit = messageEdit;
295  }
296
297  @java.lang.SuppressWarnings("all")
298  public PostbackItem getPostback() {
299    return this.postback;
300  }
301
302  @java.lang.SuppressWarnings("all")
303  public void setPostback(final PostbackItem postback) {
304    this.postback = postback;
305  }
306
307  @java.lang.SuppressWarnings("all")
308  public OptinItem getOptin() {
309    return this.optin;
310  }
311
312  @java.lang.SuppressWarnings("all")
313  public void setOptin(final OptinItem optin) {
314    this.optin = optin;
315  }
316
317  @java.lang.SuppressWarnings("all")
318  public AccountLinkingItem getAccountLinking() {
319    return this.accountLinking;
320  }
321
322  @java.lang.SuppressWarnings("all")
323  public void setAccountLinking(final AccountLinkingItem accountLinking) {
324    this.accountLinking = accountLinking;
325  }
326
327  @java.lang.SuppressWarnings("all")
328  public CheckoutUpdateItem getCheckoutUpdate() {
329    return this.checkoutUpdate;
330  }
331
332  @java.lang.SuppressWarnings("all")
333  public void setCheckoutUpdate(final CheckoutUpdateItem checkoutUpdate) {
334    this.checkoutUpdate = checkoutUpdate;
335  }
336
337  @java.lang.SuppressWarnings("all")
338  public PaymentItem getPayment() {
339    return this.payment;
340  }
341
342  @java.lang.SuppressWarnings("all")
343  public void setPayment(final PaymentItem payment) {
344    this.payment = payment;
345  }
346
347  @java.lang.SuppressWarnings("all")
348  public ReferralItem getReferral() {
349    return this.referral;
350  }
351
352  @java.lang.SuppressWarnings("all")
353  public void setReferral(final ReferralItem referral) {
354    this.referral = referral;
355  }
356
357  @java.lang.SuppressWarnings("all")
358  public PolicyEnforcementItem getPolicyEnforcement() {
359    return this.policyEnforcement;
360  }
361
362  @java.lang.SuppressWarnings("all")
363  public void setPolicyEnforcement(final PolicyEnforcementItem policyEnforcement) {
364    this.policyEnforcement = policyEnforcement;
365  }
366
367  @java.lang.SuppressWarnings("all")
368  public PassThreadControlItem getPassThreadControl() {
369    return this.passThreadControl;
370  }
371
372  @java.lang.SuppressWarnings("all")
373  public void setPassThreadControl(final PassThreadControlItem passThreadControl) {
374    this.passThreadControl = passThreadControl;
375  }
376
377  @java.lang.SuppressWarnings("all")
378  public TakeThreadControlItem getTakeThreadControl() {
379    return this.takeThreadControl;
380  }
381
382  @java.lang.SuppressWarnings("all")
383  public void setTakeThreadControl(final TakeThreadControlItem takeThreadControl) {
384    this.takeThreadControl = takeThreadControl;
385  }
386
387  @java.lang.SuppressWarnings("all")
388  public RequestThreadControlItem getRequestThreadControl() {
389    return this.requestThreadControl;
390  }
391
392  @java.lang.SuppressWarnings("all")
393  public void setRequestThreadControl(final RequestThreadControlItem requestThreadControl) {
394    this.requestThreadControl = requestThreadControl;
395  }
396
397  @java.lang.SuppressWarnings("all")
398  public AppRoles getAppRoles() {
399    return this.appRoles;
400  }
401
402  @java.lang.SuppressWarnings("all")
403  public void setAppRoles(final AppRoles appRoles) {
404    this.appRoles = appRoles;
405  }
406
407  @java.lang.SuppressWarnings("all")
408  public PriorMessage getPriorMessage() {
409    return this.priorMessage;
410  }
411
412  @java.lang.SuppressWarnings("all")
413  public void setPriorMessage(final PriorMessage priorMessage) {
414    this.priorMessage = priorMessage;
415  }
416
417  @java.lang.SuppressWarnings("all")
418  public MessageReaction getReaction() {
419    return this.reaction;
420  }
421
422  @java.lang.SuppressWarnings("all")
423  public void setReaction(final MessageReaction reaction) {
424    this.reaction = reaction;
425  }
426}