package com.srs.web.core.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.time.Duration;

@Component // 让 Spring 扫描到
@ConfigurationProperties(prefix = "dify")
public class DifyConfig {

    /**
     * Dify 服务的基础 URL，例如：http://47.112.118.149:8100
     */
    private String baseUrl;

    /**
     * Dify API 密钥
     */
    private String apiKey;

    /**
     * 超时时间配置（可选）
     */
    private Duration timeout = Duration.ofSeconds(30);

    // ================== API URLs ==================
    // 这些 URL 基于 baseUrl 自动生成，不直接暴露在配置文件中
    private String apiUrl;
    private String feedbackBaseUrl;
    private String apiFeedbackUrl;
    private String apiHistoryUrl;
    private String conversationsUrl;
    private String filesUrl;

    // ================== Redis 缓存配置 ==================
    private String conversationCachePrefix = "dify:conversation:id:";
    private int conversationCacheExpireHours = 1;

    // -------------------- Getters and Setters --------------------

    public String getBaseUrl() {
        return baseUrl;
    }

    public void setBaseUrl(String baseUrl) {
        this.baseUrl = baseUrl;
    }

    public String getApiKey() {
        return apiKey;
    }

    public void setApiKey(String apiKey) {
        this.apiKey = apiKey;
    }

    public Duration getTimeout() {
        return timeout;
    }

    public void setTimeout(Duration timeout) {
        this.timeout = timeout;
    }

    public String getApiUrl() {
        return baseUrl + "/v1/chat-messages";
    }

    public String getFeedbackBaseUrl() {
        return baseUrl + "/v1/messages";
    }

    public String getApiFeedbackUrl() {
        return baseUrl + "/v1/app/feedbacks?page=";
    }

    public String getApiHistoryUrl() {
        return baseUrl + "/v1/messages";
    }

    public String getConversationsUrl() {
        return baseUrl + "/v1/conversations";
    }

    public String getFilesUrl() {
        return baseUrl + "/v1/files/upload";
    }

    public String getConversationCachePrefix() {
        return conversationCachePrefix;
    }

    public void setConversationCachePrefix(String conversationCachePrefix) {
        this.conversationCachePrefix = conversationCachePrefix;
    }

    public int getConversationCacheExpireHours() {
        return conversationCacheExpireHours;
    }

    public void setConversationCacheExpireHours(int conversationCacheExpireHours) {
        this.conversationCacheExpireHours = conversationCacheExpireHours;
    }
}
