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.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 @lombok.Generated 075 public String getUrl() { 076 return this.url; 077 } 078 079 @java.lang.SuppressWarnings("all") 080 @lombok.Generated 081 public Boolean getIsReusable() { 082 return this.isReusable; 083 } 084 } 085 086 087 private static class UploadPayload extends AbstractFacebookType implements MediaAttachmentPayload { 088 @Facebook("is_reusable") 089 private Boolean isReusable; 090 091 public UploadPayload() { 092 // empty constructor 093 } 094 095 @Override 096 public void setIsReusable(boolean isReusable) { 097 this.isReusable = isReusable; 098 } 099 100 @java.lang.SuppressWarnings("all") 101 @lombok.Generated 102 public Boolean getIsReusable() { 103 return this.isReusable; 104 } 105 } 106 107 108 private static class ReuseIdPayload extends AbstractFacebookType implements MediaAttachmentPayload { 109 @Facebook("attachment_id") 110 private String attachmentId; 111 112 public ReuseIdPayload(String urlString) { 113 attachmentId = urlString; 114 } 115 116 @Override 117 public void setIsReusable(boolean isReusable) { 118 // ignore this here 119 } 120 121 @java.lang.SuppressWarnings("all") 122 @lombok.Generated 123 public String getAttachmentId() { 124 return this.attachmentId; 125 } 126 } 127 128 129 private static class MediaTemplatePayload extends AbstractFacebookType implements MediaAttachmentPayload { 130 @Facebook("template_type") 131 private String templateType = "media"; 132 @Facebook 133 private List<MediaTemplateElement> elements; 134 135 public MediaTemplatePayload(List<MediaTemplateElement> elements) { 136 this.elements = elements; 137 } 138 139 @Override 140 public void setIsReusable(boolean isReusable) { 141 // ignore this here 142 } 143 144 @java.lang.SuppressWarnings("all") 145 @lombok.Generated 146 public String getTemplateType() { 147 return this.templateType; 148 } 149 } 150 151 152 private interface MediaAttachmentPayload extends Serializable { 153 void setIsReusable(boolean isReusable); 154 } 155 156 157 public interface MediaTemplateElement extends Serializable { 158 void addButton(AbstractButton button); 159 } 160 161 162 public enum Type { 163 IMAGE, VIDEO, AUDIO, FILE, TEMPLATE; 164 } 165 166 167 public enum MediaType { 168 IMAGE, VIDEO; 169 } 170 171 @java.lang.SuppressWarnings("all") 172 @lombok.Generated 173 public MediaAttachmentPayload getPayload() { 174 return this.payload; 175 } 176}