package com.kt.ai.client.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

/**
 * Claude API 응답 DTO
 * API Docs: https://docs.anthropic.com/claude/reference/messages_post
 *
 * @author AI Service Team
 * @since 1.0.0
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ClaudeResponse {
    /**
     * 응답 ID
     */
    private String id;

    /**
     * 타입 (message)
     */
    private String type;

    /**
     * 역할 (assistant)
     */
    private String role;

    /**
     * 콘텐츠 목록
     */
    private List<Content> content;

    /**
     * 모델명
     */
    private String model;

    /**
     * 중단 이유 (end_turn, max_tokens, stop_sequence)
     */
    @JsonProperty("stop_reason")
    private String stopReason;

    /**
     * 사용량
     */
    private Usage usage;

    /**
     * 콘텐츠
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    public static class Content {
        /**
         * 타입 (text)
         */
        private String type;

        /**
         * 텍스트 내용
         */
        private String text;
    }

    /**
     * 토큰 사용량
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    public static class Usage {
        /**
         * 입력 토큰 수
         */
        @JsonProperty("input_tokens")
        private Integer inputTokens;

        /**
         * 출력 토큰 수
         */
        @JsonProperty("output_tokens")
        private Integer outputTokens;
    }

    /**
     * 텍스트 내용 추출
     */
    public String extractText() {
        if (content != null && !content.isEmpty()) {
            return content.get(0).getText();
        }
        return null;
    }
}
