001// Generated by delombok at Thu Aug 13 13:56:44 UTC 2026
002/*
003 * Copyright (c) 2010-2026 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.Date;
028import java.util.List;
029import com.restfb.Facebook;
030import com.restfb.JsonMapper.JsonMappingCompleted;
031import com.restfb.json.Json;
032import com.restfb.json.JsonObject;
033import com.restfb.types.features.HasCreatedTime;
034
035/**
036 * Represents the <a href="https://developers.facebook.com/docs/graph-api/reference/video/likes/">Video Likes Graph API
037 * type</a> and the <a href="https://developers.facebook.com/docs/graph-api/reference/post/likes/">Post Likes Graph API
038 * type</a>
039 *
040 * @author <a href="http://restfb.com">Mark Allen</a>
041 */
042public class Likes extends AbstractFacebookType {
043  /**
044   * The number of likes.
045   */
046  @Facebook
047  private Long totalCount = 0L;
048  /**
049   * returns if the user can like the object
050   */
051  private Boolean canLike;
052  /**
053   * returns if the user has liked the object
054   */
055  private Boolean hasLiked;
056  @Facebook("can_like")
057  private Boolean openGraphCanLike;
058  @Facebook("user_likes")
059  private Boolean openGraphUserLikes;
060  @Facebook("count")
061  private Long openGraphCount = 0L;
062  @Facebook
063  private String summary;
064  @Facebook
065  private List<LikeItem> data = new ArrayList<>();
066  private static final long serialVersionUID = 1L;
067
068  /**
069   * The likes.
070   *
071   * @return The likes.
072   */
073  public List<LikeItem> getData() {
074    return unmodifiableList(data);
075  }
076
077  public boolean addData(LikeItem like) {
078    return data.add(like);
079  }
080
081  public boolean removeData(LikeItem like) {
082    return data.remove(like);
083  }
084
085  @JsonMappingCompleted
086  private void fillFields() {
087    JsonObject summaryObject = null;
088    if (summary != null) {
089      summaryObject = Json.parse(summary).asObject();
090    }
091    fillTotalCount(summaryObject);
092    fillHasLiked(summaryObject);
093    fillCanLike(summaryObject);
094  }
095
096  /**
097   * add change count value, if summary is set and count is empty
098   */
099  private void fillTotalCount(JsonObject summary) {
100    if (totalCount == 0 && summary != null && summary.get("total_count") != null) {
101      totalCount = summary.getLong("total_count", totalCount);
102    }
103    if (openGraphCount != 0) {
104      totalCount = openGraphCount;
105    }
106  }
107
108  /**
109   * fill <code>has_liked</code> from summary, in case of open graph object use user_likes instead
110   */
111  private void fillHasLiked(JsonObject summary) {
112    if (summary != null && summary.get("has_liked") != null) {
113      hasLiked = summary.get("has_liked").asBoolean();
114    }
115    if (hasLiked == null && openGraphUserLikes != null) {
116      hasLiked = openGraphUserLikes;
117    }
118  }
119
120  private void fillCanLike(JsonObject summary) {
121    if (summary != null && summary.get("can_like") != null) {
122      canLike = summary.get("can_like").asBoolean();
123    }
124    if (canLike == null && openGraphCanLike != null) {
125      canLike = openGraphCanLike;
126    }
127  }
128
129
130  public static class LikeItem extends NamedFacebookType implements HasCreatedTime {
131    /**
132     * created time is the date the Like was created.
133     * <p>
134     * may be null if Facebook does not provide this information
135     */
136    @Facebook("created_time")
137    private Date createdTime;
138
139    /**
140     * created time is the date the Like was created.
141     * <p>
142     * may be null if Facebook does not provide this information
143     */
144    @Override
145    @java.lang.SuppressWarnings("all")
146    @lombok.Generated
147    public Date getCreatedTime() {
148      return this.createdTime;
149    }
150
151    /**
152     * created time is the date the Like was created.
153     * <p>
154     * may be null if Facebook does not provide this information
155     */
156    @java.lang.SuppressWarnings("all")
157    @lombok.Generated
158    public void setCreatedTime(final Date createdTime) {
159      this.createdTime = createdTime;
160    }
161  }
162
163  /**
164   * The number of likes.
165   *
166   * @return The number of likes.
167   */
168  @java.lang.SuppressWarnings("all")
169  @lombok.Generated
170  public Long getTotalCount() {
171    return this.totalCount;
172  }
173
174  /**
175   * The number of likes.
176   */
177  @java.lang.SuppressWarnings("all")
178  @lombok.Generated
179  public void setTotalCount(final Long totalCount) {
180    this.totalCount = totalCount;
181  }
182
183  /**
184   * returns if the user can like the object
185   *
186   * @return if the user can like the object
187   */
188  @java.lang.SuppressWarnings("all")
189  @lombok.Generated
190  public Boolean getCanLike() {
191    return this.canLike;
192  }
193
194  /**
195   * returns if the user can like the object
196   */
197  @java.lang.SuppressWarnings("all")
198  @lombok.Generated
199  public void setCanLike(final Boolean canLike) {
200    this.canLike = canLike;
201  }
202
203  /**
204   * returns if the user has liked the object
205   *
206   * @return if the user has liked the object
207   */
208  @java.lang.SuppressWarnings("all")
209  @lombok.Generated
210  public Boolean getHasLiked() {
211    return this.hasLiked;
212  }
213
214  /**
215   * returns if the user has liked the object
216   */
217  @java.lang.SuppressWarnings("all")
218  @lombok.Generated
219  public void setHasLiked(final Boolean hasLiked) {
220    this.hasLiked = hasLiked;
221  }
222}