package top.tqx.demo_1.config;

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

@Data
@Component
@ConfigurationProperties(prefix = "ai.api")
public class AiApiConfig {

    private String host = "rag-service";
    
    private Integer port = 5001;
    
    private ChatConfig chat = new ChatConfig();
    
    private WorkflowConfig workflow = new WorkflowConfig();
    
    private DocumentConfig document = new DocumentConfig();
    
    private CollectionConfig collection = new CollectionConfig();
    
    private SyncConfig sync = new SyncConfig();
    
    private ExamConfig exam = new ExamConfig();
    
    @Data
    public static class ChatConfig {
        private String chat = "/chat";
        private String rag = "/rag";
        private String ragStream = "/rag";
        private String search = "/search";
    }
    
    @Data
    public static class WorkflowConfig {
        private String run = "/v1/workflows/run";
        private String stop = "/v1/workflows/stop";
    }
    
    @Data
    public static class DocumentConfig {
        private String upload = "/documents/upload";
        private String batchUpload = "/documents/batch-upload";
        private String list = "/documents/list";
        private String delete = "/documents";
        private String chunks = "/documents/{path}/chunks";
        private String deprecate = "/collections/{name}/documents/{filename}/deprecate";
        private String restore = "/collections/{name}/documents/{filename}/restore";
        private String versions = "/collections/{name}/documents/{filename}/versions";
    }
    
    @Data
    public static class CollectionConfig {
        private String list = "/collections";
        private String create = "/collections";
        private String update = "/collections/{name}";
        private String delete = "/collections/{name}";
        private String chunks = "/collections/{name}/chunks";
    }
    
    @Data
    public static class SyncConfig {
        private String trigger = "/sync";
        private String status = "/sync/status";
    }
    
    @Data
    public static class FeedbackConfig {
        private String submit = "/feedback";
        private String list = "/feedback/list";
        private String stats = "/feedback/stats";
        private String badCases = "/feedback/bad-cases";
    }
    
    @Data
    public static class FAQConfig {
        private String faq = "/faq";
        private String suggestions = "/faq/suggestions";
        private String approve = "/faq/suggestions/{id}/approve";
        private String reject = "/faq/suggestions/{id}/reject";
    }
    
    @Data
    public static class ImageConfig {
        private String list = "/images/list";
        private String image = "/images/{image_id}";
        private String info = "/images/{image_id}/info";
        private String stats = "/images/stats";
    }
    
    @Data
    public static class ReportConfig {
        private String weekly = "/reports/weekly";
        private String monthly = "/reports/monthly";
    }
    
    @Data
    public static class KBRouteConfig {
        private String route = "/kb/route";
    }
    
    @Data
    public static class SearchConfig {
        private String search = "/search";
    }
    
    @Data
    public static class ExamConfig {
        private String generate = "/exam/generate";
        private String generateSmart = "/exam/generate-smart";
        private String grade = "/exam/grade";
    }
    
    private FeedbackConfig feedback = new FeedbackConfig();
    private FAQConfig faq = new FAQConfig();
    private ImageConfig images = new ImageConfig();
    private ReportConfig reports = new ReportConfig();
    private KBRouteConfig kbRoute = new KBRouteConfig();
    private SearchConfig search = new SearchConfig();
    private ChunkConfig chunk = new ChunkConfig();
    
    @Data
    public static class ChunkConfig {
        private String create = "/chunks";
        private String update = "/chunks/{id}";
        private String delete = "/chunks/{id}";
        private String documentChunks = "/documents/{path}/chunks";
    }
    
    public String getFullUrl(String path) {
        String baseUrl = "http://" + host + ":" + port;
        if (path == null || path.isEmpty()) {
            return baseUrl;
        }
        String requestPath = path.startsWith("/") ? path : "/" + path;
        return baseUrl + requestPath;
    }
}