/*
 * Copyright 2023-2024 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.yanzhu.module.ai.framework.ai.core.model.siliconflow;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;

/**
 * 硅基流动 Image API
 *
 * @author zzt
 */
public class SiliconFlowImageApi {

    private final RestTemplate restTemplate;
    private final String apiKey;

    public SiliconFlowImageApi(String apiKey) {
        this(SiliconFlowApiConstants.DEFAULT_BASE_URL, apiKey);
    }

    public SiliconFlowImageApi(String baseUrl, String apiKey) {
        this.apiKey = apiKey;
        this.restTemplate = new RestTemplate();
    }

    public String generateImage(String prompt) {
        // 简化实现，实际应该调用硅基流动API
        // 这里应该发送HTTP请求到硅基流动的图像生成API
        SiliconflowImageRequest request = new SiliconflowImageRequest(prompt, SiliconFlowApiConstants.MODEL_DEFAULT);
        
        // 这里需要实现实际的HTTP调用逻辑
        // 由于这是一个简化的实现，返回一个示例URL
        return "https://example.com/generated-image.png";
    }

    // @formatter:off
    @JsonInclude(JsonInclude.Include.NON_NULL)
    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public static class SiliconflowImageRequest {
        @JsonProperty("prompt")
        private String prompt;

        @JsonProperty("model")
        private String model;

        @JsonProperty("batch_size")
        private Integer batchSize;

        @JsonProperty("negative_prompt")
        private String negativePrompt;

        @JsonProperty("seed")
        private Integer seed;

        @JsonProperty("num_inference_steps")
        private Integer numInferenceSteps;

        @JsonProperty("guidance_scale")
        private Float guidanceScale;

        @JsonProperty("image")
        private String image;

        public SiliconflowImageRequest(String prompt, String model) {
            this.prompt = prompt;
            this.model = model;
        }
    }
    // @formatter:on
}