package com.dora.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * 工具服务相关DTO
 */
public class ToolDto {

    /**
     * 工具调用请求
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    public static class CallRequest {
        /**
         * 工具编码
         */
        private String toolCode;
        
        /**
         * 请求参数
         */
        private Map<String, Object> params;
    }

    /**
     * 工具调用响应
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    public static class CallResponse {
        /**
         * 调用流水号
         */
        private String usageNo;
        
        /**
         * 消耗积分
         */
        private Integer pointsCost;
        
        /**
         * 剩余积分
         */
        private Integer remainingPoints;
        
        /**
         * API响应数据
         */
        private Object data;
    }

    /**
     * 工具配置创建/更新请求
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    public static class ConfigRequest {
        private String toolCode;
        private String toolName;
        private String category;
        private String description;
        private String apiEndpoint;
        private String requestMethod;
        private Integer pointsCost;
        private Integer isEnabled;
        private Integer sortOrder;
    }

    /**
     * 工具配置响应
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    public static class ConfigResponse {
        private Long id;
        private String toolCode;
        private String toolName;
        private String category;
        private String description;
        private String apiEndpoint;
        private String requestMethod;
        private Integer pointsCost;
        private Integer isEnabled;
        private Integer sortOrder;
        private LocalDateTime createTime;
        private LocalDateTime updateTime;
    }

    /**
     * 工具列表响应（用户端）
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    public static class ToolListItem {
        private String toolCode;
        private String toolName;
        private String category;
        private String description;
        private Integer pointsCost;
    }

    /**
     * 工具使用记录响应
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    public static class UsageLogResponse {
        private String usageNo;
        private String toolCode;
        private String toolName;
        private Integer pointsCost;
        private String status;
        private LocalDateTime createTime;
    }

    /**
     * 工具使用记录分页响应
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    public static class UsageLogPageResponse {
        private List<UsageLogResponse> records;
        private Long total;
        private Integer page;
        private Integer size;
    }

    /**
     * 每日统计响应
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    public static class DailyStatsResponse {
        private LocalDate statsDate;
        private String toolCode;
        private String toolName;
        private Integer totalCalls;
        private Integer successCalls;
        private Integer failedCalls;
        private Integer totalPointsCost;
        private Integer uniqueUsers;
    }

    /**
     * 统计汇总响应
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    public static class StatsSummaryResponse {
        /**
         * 总调用次数
         */
        private Long totalCalls;
        
        /**
         * 成功次数
         */
        private Long successCalls;
        
        /**
         * 失败次数
         */
        private Long failedCalls;
        
        /**
         * 总消耗积分
         */
        private Long totalPointsCost;
        
        /**
         * 独立用户数
         */
        private Long uniqueUsers;
        
        /**
         * 按工具分类统计
         */
        private List<ToolStatsItem> toolStats;
    }

    /**
     * 工具统计项
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    public static class ToolStatsItem {
        private String toolCode;
        private String toolName;
        private String category;
        private Long totalCalls;
        private Long successCalls;
        private Long totalPointsCost;
    }

    /**
     * 统计查询请求
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    public static class StatsQueryRequest {
        /**
         * 开始日期
         */
        private LocalDate startDate;
        
        /**
         * 结束日期
         */
        private LocalDate endDate;
        
        /**
         * 工具编码（可选）
         */
        private String toolCode;
        
        /**
         * 分类（可选）
         */
        private String category;
    }
}
