001// Generated by delombok at Tue Dec 10 13:42:03 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.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(Type type) { 044 setType(type.toString().toLowerCase()); 045 payload = new UploadPayload(); 046 } 047 048 public MediaAttachment(List<MediaTemplateElement> elements) { 049 setType(Type.TEMPLATE.toString().toLowerCase()); 050 payload = new MediaTemplatePayload(elements); 051 } 052 053 public void setIsReusable(boolean isReusable) { 054 payload.setIsReusable(isReusable); 055 } 056 057 058 private static class UrlPayload extends AbstractFacebookType implements MediaAttachmentPayload { 059 @Facebook 060 private String url; 061 @Facebook("is_reusable") 062 private Boolean isReusable; 063 064 public UrlPayload(String urlString) { 065 url = urlString; 066 } 067 068 @Override 069 public void setIsReusable(boolean isReusable) { 070 this.isReusable = isReusable; 071 } 072 073 @java.lang.SuppressWarnings("all") 074 public String getUrl() { 075 return this.url; 076 } 077 078 @java.lang.SuppressWarnings("all") 079 public Boolean getIsReusable() { 080 return this.isReusable; 081 } 082 } 083 084 085 private static class UploadPayload extends AbstractFacebookType implements MediaAttachmentPayload { 086 @Facebook("is_reusable") 087 private Boolean isReusable; 088 089 public UploadPayload() { 090 // empty constructor 091 } 092 093 @Override 094 public void setIsReusable(boolean isReusable) { 095 this.isReusable = isReusable; 096 } 097 098 @java.lang.SuppressWarnings("all") 099 public Boolean getIsReusable() { 100 return this.isReusable; 101 } 102 } 103 104 105 private static class ReuseIdPayload extends AbstractFacebookType implements MediaAttachmentPayload { 106 @Facebook("attachment_id") 107 private String attachmentId; 108 109 public ReuseIdPayload(String urlString) { 110 attachmentId = urlString; 111 } 112 113 @Override 114 public void setIsReusable(boolean isReusable) { 115 // ignore this here 116 } 117 118 @java.lang.SuppressWarnings("all") 119 public String getAttachmentId() { 120 return this.attachmentId; 121 } 122 } 123 124 125 private static class MediaTemplatePayload extends AbstractFacebookType implements MediaAttachmentPayload { 126 @Facebook("template_type") 127 private String templateType = "media"; 128 @Facebook 129 private List<MediaTemplateElement> elements; 130 131 public MediaTemplatePayload(List<MediaTemplateElement> elements) { 132 this.elements = elements; 133 } 134 135 @Override 136 public void setIsReusable(boolean isReusable) { 137 // ignore this here 138 } 139 140 @java.lang.SuppressWarnings("all") 141 public String getTemplateType() { 142 return this.templateType; 143 } 144 } 145 146 147 private interface MediaAttachmentPayload extends Serializable { 148 void setIsReusable(boolean isReusable); 149 } 150 151 152 public interface MediaTemplateElement extends Serializable { 153 void addButton(AbstractButton button); 154 } 155 156 157 public enum Type { 158 IMAGE, VIDEO, AUDIO, FILE, TEMPLATE; 159 } 160 161 162 public enum MediaType { 163 IMAGE, VIDEO; 164 } 165 166 @java.lang.SuppressWarnings("all") 167 public MediaAttachmentPayload getPayload() { 168 return this.payload; 169 } 170}