001// Generated by delombok at Fri Nov 22 22:30:55 CET 2019
002/**
003 * Copyright (c) 2010-2019 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.send;
024
025import java.util.ArrayList;
026import java.util.Collections;
027import java.util.List;
028import com.restfb.Facebook;
029import com.restfb.annotation.GraphAPI;
030import com.restfb.exception.FacebookPreconditionException;
031
032/**
033 * Implementation of <a href="https://developers.facebook.com/docs/messenger-platform/send-messages/template/list/">Vertical List View</a>
034 *
035 * @deprecated with Graph API 4.0 this is no longer supported
036 */
037@Deprecated
038@GraphAPI(until = "4.0")
039public class ListTemplatePayload extends SharableTemplatePayload implements IsBroadcastPayload {
040  @Facebook
041  private List<ListViewElement> elements;
042  /**
043   * Value must be large or compact. Default to large if not specified
044   */
045  @Facebook("top_element_style")
046  private TopElementStyleEnum topElementStyle;
047  @Facebook
048  private List<AbstractButton> buttons;
049
050  public ListTemplatePayload(List<ListViewElement> listViewElements) {
051    setTemplateType("list");
052    if (listViewElements == null) {
053      throw new FacebookPreconditionException("List of elements may not be \'null\'");
054    }
055    if (listViewElements.isEmpty() || listViewElements.size() < 2) {
056      throw new FacebookPreconditionException("List of elements needs to contain a minimum of 2");
057    }
058    if (listViewElements.size() > 4) {
059      throw new FacebookPreconditionException("List of elements can contain a maximum of 4 elements");
060    }
061    elements = Collections.unmodifiableList(listViewElements);
062  }
063
064  public boolean addButton(AbstractButton button) {
065    if (buttons == null) {
066      buttons = new ArrayList<>();
067    }
068    if (buttons.size() == 1) {
069      throw new FacebookPreconditionException("maximum of associated buttons is 1");
070    }
071    return buttons.add(button);
072  }
073
074  public List<AbstractButton> getButtons() {
075    return Collections.unmodifiableList(buttons);
076  }
077
078  public List<ListViewElement> getElements() {
079    return Collections.unmodifiableList(elements);
080  }
081
082
083  public enum TopElementStyleEnum {
084    large, compact // NOSONAR
085    ;
086  }
087
088  /**
089   * Value must be large or compact. Default to large if not specified
090   */
091  @java.lang.SuppressWarnings("all")
092  public TopElementStyleEnum getTopElementStyle() {
093    return this.topElementStyle;
094  }
095
096  /**
097   * Value must be large or compact. Default to large if not specified
098   */
099  @java.lang.SuppressWarnings("all")
100  public void setTopElementStyle(final TopElementStyleEnum topElementStyle) {
101    this.topElementStyle = topElementStyle;
102  }
103}