package com.jambotronGroup.jambotron.ZhiPuAi;

import com.jambotronGroup.jambotron.model.NameValueItem;
import org.springframework.ai.image.Image;
import org.springframework.ai.image.ImagePrompt;
import org.springframework.ai.image.ImageResponse;
import org.springframework.ai.zhipuai.ZhiPuAiImageModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin(origins = "http://localhost:4200, https://pony-sincere-chimp.ngrok-free.app/", maxAge = 3600, allowCredentials="true")
@RestController
@RequestMapping("/api/zhipuai")
public class ImageController {

    @Autowired
    ZhiPuAiImageService _zhiPuAiImageService;

    @GetMapping("/image/{query}")
    public ResponseEntity<Image> getImage(@PathVariable("query") String query) {
        try {
            Image returnValue  =  _zhiPuAiImageService.generateImage(query).getResult().getOutput();
            //userRepository.findAll().forEach(users::add);


            if (returnValue == null) {
                return new ResponseEntity<>(HttpStatus.NO_CONTENT);
            }

            return new ResponseEntity<>(returnValue, HttpStatus.OK);
        } catch (Exception e) {
            return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
        }
    }
}