001// Generated by delombok at Sun Jul 07 22:01:31 CEST 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.exception.FacebookPreconditionException;
030
031public class ListTemplatePayload extends SharableTemplatePayload implements IsBroadcastPayload {
032  @Facebook
033  private List<ListViewElement> elements;
034  /**
035   * Value must be large or compact. Default to large if not specified
036   */
037  @Facebook("top_element_style")
038  private TopElementStyleEnum topElementStyle;
039  @Facebook
040  private List<AbstractButton> buttons;
041
042  public ListTemplatePayload(List<ListViewElement> listViewElements) {
043    setTemplateType("list");
044    if (listViewElements == null) {
045      throw new FacebookPreconditionException("List of elements may not be \'null\'");
046    }
047    if (listViewElements.isEmpty() || listViewElements.size() < 2) {
048      throw new FacebookPreconditionException("List of elements needs to contain a minimum of 2");
049    }
050    if (listViewElements.size() > 4) {
051      throw new FacebookPreconditionException("List of elements can contain a maximum of 4 elements");
052    }
053    elements = Collections.unmodifiableList(listViewElements);
054  }
055
056  public boolean addButton(AbstractButton button) {
057    if (buttons == null) {
058      buttons = new ArrayList<>();
059    }
060    if (buttons.size() == 1) {
061      throw new FacebookPreconditionException("maximum of associated buttons is 1");
062    }
063    return buttons.add(button);
064  }
065
066  public List<AbstractButton> getButtons() {
067    return Collections.unmodifiableList(buttons);
068  }
069
070  public List<ListViewElement> getElements() {
071    return Collections.unmodifiableList(elements);
072  }
073
074
075  public enum TopElementStyleEnum {
076    large, compact // NOSONAR
077    ;
078  }
079
080  /**
081   * Value must be large or compact. Default to large if not specified
082   */
083  @java.lang.SuppressWarnings("all")
084  public TopElementStyleEnum getTopElementStyle() {
085    return this.topElementStyle;
086  }
087
088  /**
089   * Value must be large or compact. Default to large if not specified
090   */
091  @java.lang.SuppressWarnings("all")
092  public void setTopElementStyle(final TopElementStyleEnum topElementStyle) {
093    this.topElementStyle = topElementStyle;
094  }
095}