001/* 002 * Copyright (c) 2023-2026, Agents-Flex (fuhai999@gmail.com). 003 * <p> 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * <p> 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * <p> 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package com.agentsflex.core.model.image; 017 018import com.agentsflex.core.util.Metadata; 019 020import java.util.ArrayList; 021import java.util.Collections; 022import java.util.List; 023 024public class ImageResponse extends Metadata { 025 private List<Image> images; 026 private boolean error; 027 private String errorMessage; 028 029 030 public static ImageResponse error(String errMessage) { 031 ImageResponse imageResponse = new ImageResponse(); 032 imageResponse.setError(true); 033 imageResponse.setErrorMessage(errMessage); 034 return imageResponse; 035 } 036 037 public List<Image> getImages() { 038 return images != null ? images : Collections.emptyList(); 039 } 040 041 public void setImages(List<Image> images) { 042 this.images = images; 043 } 044 045 046 public void addImage(String url) { 047 if (this.images == null) { 048 this.images = new ArrayList<>(); 049 } 050 051 this.images.add(Image.ofUrl(url)); 052 } 053 054 public void addImage(byte[] bytes) { 055 if (this.images == null) { 056 this.images = new ArrayList<>(); 057 } 058 059 this.images.add(Image.ofBytes(bytes)); 060 } 061 062 public boolean isError() { 063 return error; 064 } 065 066 public void setError(boolean error) { 067 this.error = error; 068 } 069 070 public String getErrorMessage() { 071 return errorMessage; 072 } 073 074 public void setErrorMessage(String errorMessage) { 075 this.errorMessage = errorMessage; 076 } 077 078 @Override 079 public String toString() { 080 return "ImageResponse{" + 081 "images=" + images + 082 ", error=" + error + 083 ", errorMessage='" + errorMessage + '\'' + 084 ", metadataMap=" + metadataMap + 085 '}'; 086 } 087}