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.io.Serializable;
026import java.util.List;
027import com.restfb.Facebook;
028import com.restfb.types.AbstractFacebookType;
029
030public class MediaAttachment extends MessageAttachment {
031  @Facebook
032  private MediaAttachmentPayload payload;
033
034  public MediaAttachment(Type type, String imageUrl) {
035    setType(type.toString().toLowerCase());
036    if (imageUrl.matches("^\\d+$")) {
037      payload = new ReuseIdPayload(imageUrl);
038    } else {
039      payload = new UrlPayload(imageUrl);
040    }
041  }
042
043  public MediaAttachment(List<MediaTemplateElement> elements) {
044    setType(Type.TEMPLATE.toString().toLowerCase());
045    payload = new MediaTemplatePayload(elements);
046  }
047
048  public void setIsReusable(boolean isReusable) {
049    payload.setIsReusable(isReusable);
050  }
051
052
053  private static class UrlPayload extends AbstractFacebookType implements MediaAttachmentPayload {
054    @Facebook
055    private String url;
056    @Facebook("is_reusable")
057    private Boolean isReusable;
058
059    public UrlPayload(String urlString) {
060      url = urlString;
061    }
062
063    @Override
064    public void setIsReusable(boolean isReusable) {
065      this.isReusable = isReusable;
066    }
067
068    @java.lang.SuppressWarnings("all")
069    public String getUrl() {
070      return this.url;
071    }
072
073    @java.lang.SuppressWarnings("all")
074    public Boolean getIsReusable() {
075      return this.isReusable;
076    }
077  }
078
079
080  private static class ReuseIdPayload extends AbstractFacebookType implements MediaAttachmentPayload {
081    @Facebook("attachment_id")
082    private String attachmentId;
083
084    public ReuseIdPayload(String urlString) {
085      attachmentId = urlString;
086    }
087
088    @Override
089    public void setIsReusable(boolean isReusable) {
090      // ignore this here
091    }
092
093    @java.lang.SuppressWarnings("all")
094    public String getAttachmentId() {
095      return this.attachmentId;
096    }
097  }
098
099
100  private static class MediaTemplatePayload extends AbstractFacebookType implements MediaAttachmentPayload {
101    @Facebook("template_type")
102    private String templateType = "media";
103    @Facebook
104    private List<MediaTemplateElement> elements;
105
106    public MediaTemplatePayload(List<MediaTemplateElement> elements) {
107      this.elements = elements;
108    }
109
110    @Override
111    public void setIsReusable(boolean isReusable) {
112      // ignore this here
113    }
114
115    @java.lang.SuppressWarnings("all")
116    public String getTemplateType() {
117      return this.templateType;
118    }
119  }
120
121
122  private interface MediaAttachmentPayload extends Serializable {
123    void setIsReusable(boolean isReusable);
124  }
125
126
127  public interface MediaTemplateElement extends Serializable {
128    void addButton(WebButton button);
129  }
130
131
132  public enum Type {
133    IMAGE, VIDEO, AUDIO, FILE, TEMPLATE;
134  }
135
136
137  public enum MediaType {
138    IMAGE, VIDEO;
139  }
140
141  @java.lang.SuppressWarnings("all")
142  public MediaAttachmentPayload getPayload() {
143    return this.payload;
144  }
145}