package com.dora.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.time.LocalDateTime;

/**
 * API密钥DTO
 */
@Data
@Schema(description = "API密钥信息")
public class ApiKeyDTO {

    /**
     * API密钥值
     */
    @Schema(description = "API密钥值", example = "ak_1234567890abcdef1234567890abcdef")
    private String keyValue;

    /**
     * 是否启用
     */
    @Schema(description = "是否启用", example = "true")
    private Boolean isActive;

    /**
     * 最后使用时间
     */
    @Schema(description = "最后使用时间", example = "2024-12-01T15:30:00")
    private LocalDateTime lastUsedAt;

    /**
     * 创建时间
     */
    @Schema(description = "创建时间", example = "2024-12-01T10:00:00")
    private LocalDateTime createTime;

    /**
     * 用户会员过期时间（用于验证API密钥是否有效）
     */
    @Schema(description = "用户会员过期时间", example = "2025-01-01T10:00:00")
    private LocalDateTime membershipExpiresAt;

    /**
     * 用户角色
     */
    @Schema(description = "用户角色（0游客/1普通/2VIP/3SVIP）", example = "2")
    private Integer userRole;

    /**
     * API密钥有效期验证请求
     */
    @Data
    @Schema(description = "API密钥有效期验证请求")
    public static class ValidityCheckRequest {
        
        /**
         * API密钥值
         */
        @Schema(description = "API密钥值", example = "ak_1234567890abcdef1234567890abcdef", required = true)
        @jakarta.validation.constraints.NotBlank(message = "API密钥不能为空")
        private String keyValue;
    }

    /**
     * API密钥有效期验证响应
     */
    @Data
    @Schema(description = "API密钥有效期验证响应")
    public static class ValidityCheckResponse {
        
        /**
         * API密钥是否有效
         */
        @Schema(description = "API密钥是否有效", example = "true")
        private Boolean isValid;
        
        /**
         * 验证失败的原因（当isValid为false时）
         */
        @Schema(description = "验证失败的原因", example = "API密钥不存在")
        private String failureReason;
        
        /**
         * 用户基本信息
         */
        @Schema(description = "用户基本信息")
        private UserInfo userInfo;
        
        /**
         * API密钥信息
         */
        @Schema(description = "API密钥信息")
        private KeyInfo keyInfo;
        
        @Data
        @Schema(description = "用户基本信息")
        public static class UserInfo {
            @Schema(description = "用户ID", example = "123456")
            private Long userId;
            
            @Schema(description = "用户名", example = "user123")
            private String username;
            
            @Schema(description = "用户角色（0游客/1普通/2VIP/3SVIP）", example = "2")
            private Integer role;
            
            @Schema(description = "会员到期时间", example = "2025-01-01T10:00:00")
            private LocalDateTime membershipExpiresAt;
            
            @Schema(description = "是否为会员", example = "true")
            private Boolean isMember;
            
            @Schema(description = "会员是否已过期", example = "false")
            private Boolean isExpired;
        }
        
        @Data
        @Schema(description = "API密钥信息")
        public static class KeyInfo {
            @Schema(description = "API密钥值（脱敏显示）", example = "ak_1234****abcdef")
            private String keyValueMasked;
            
            @Schema(description = "是否启用", example = "true")
            private Boolean isActive;
            
            @Schema(description = "创建时间", example = "2024-12-01T10:00:00")
            private LocalDateTime createTime;
            
            @Schema(description = "最后使用时间", example = "2024-12-01T15:30:00")
            private LocalDateTime lastUsedAt;
        }
    }
} 