001// Generated by delombok at Wed Jan 31 21:27:42 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;
024
025import static java.util.Collections.unmodifiableList;
026import java.util.ArrayList;
027import java.util.List;
028import com.restfb.Facebook;
029import com.restfb.JsonMapper;
030import com.restfb.json.Json;
031import com.restfb.json.JsonObject;
032
033/**
034 * Represents the <a href="https://developers.facebook.com/docs/graph-api/reference/post/reactions">Reactions Type</a>
035 */
036public class Reactions extends AbstractFacebookType {
037  /**
038   * The number of reactions.
039   */
040  @Facebook
041  private Long totalCount = 0L;
042  /**
043   * returns the user reaction to the object
044   */
045  private String viewerReaction;
046  @Facebook
047  private String summary;
048  @Facebook
049  private List<ReactionItem> data = new ArrayList<>();
050  private static final long serialVersionUID = 1L;
051
052  /**
053   * The reaction list.
054   *
055   * @return The reaction list.
056   */
057  public List<ReactionItem> getData() {
058    return unmodifiableList(data);
059  }
060
061  public boolean addData(ReactionItem reaction) {
062    return data.add(reaction);
063  }
064
065  public boolean removeData(ReactionItem reaction) {
066    return data.remove(reaction);
067  }
068
069  @JsonMapper.JsonMappingCompleted
070  private void fillFields() {
071    JsonObject summaryObject = null;
072    if (summary != null) {
073      summaryObject = Json.parse(summary).asObject();
074    }
075    fillViewerReaction(summaryObject);
076    fillTotalCount(summaryObject);
077  }
078
079  private void fillViewerReaction(JsonObject summary) {
080    if (summary != null && summary.get("viewer_reaction") != null) {
081      viewerReaction = summary.get("viewer_reaction").asString();
082    }
083  }
084
085  /**
086   * add change count value, if summary is set and count is empty
087   */
088  private void fillTotalCount(JsonObject summary) {
089    if (totalCount == 0 && summary != null && summary.get("total_count") != null) {
090      totalCount = summary.getLong("total_count", totalCount);
091    }
092  }
093
094
095  /**
096   * the reaction type
097   */
098  public static class ReactionItem extends AbstractFacebookType {
099    /**
100     * the name of the user who sent the reaction
101     */
102    @Facebook
103    private String name;
104    /**
105     * the id of the user who sent the reaction
106     */
107    @Facebook
108    private String id;
109    /**
110     * type of the reaction
111     *
112     * may be {NONE, LIKE, LOVE, WOW, HAHA, SAD, ANGRY}
113     *
114     * @return type of the reaction
115     */
116    @Facebook
117    private String type;
118
119    @java.lang.SuppressWarnings("all")
120    public String getName() {
121      return this.name;
122    }
123
124    @java.lang.SuppressWarnings("all")
125    public void setName(final String name) {
126      this.name = name;
127    }
128
129    @java.lang.SuppressWarnings("all")
130    public String getId() {
131      return this.id;
132    }
133
134    @java.lang.SuppressWarnings("all")
135    public void setId(final String id) {
136      this.id = id;
137    }
138
139    @java.lang.SuppressWarnings("all")
140    public String getType() {
141      return this.type;
142    }
143
144    @java.lang.SuppressWarnings("all")
145    public void setType(final String type) {
146      this.type = type;
147    }
148  }
149
150  /**
151   * The number of reactions.
152   *
153   * @return The number of reactions.
154   */
155  @java.lang.SuppressWarnings("all")
156  public Long getTotalCount() {
157    return this.totalCount;
158  }
159
160  /**
161   * The number of reactions.
162   */
163  @java.lang.SuppressWarnings("all")
164  public void setTotalCount(final Long totalCount) {
165    this.totalCount = totalCount;
166  }
167
168  /**
169   * @return the user reaction to the object
170   */
171  @java.lang.SuppressWarnings("all")
172  public String getViewerReaction() {
173    return this.viewerReaction;
174  }
175
176  /**
177   * returns the user reaction to the object
178   */
179  @java.lang.SuppressWarnings("all")
180  public void setViewerReaction(final String viewerReaction) {
181    this.viewerReaction = viewerReaction;
182  }
183}