package com.pablotj.ai.chat.application.dto;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import java.time.Instant;
import java.util.List;

/**
 * Data Transfer Object for complete conversation data.
 */
@Schema(description = "Complete conversation with messages")
public record ConversationDto(

        @Schema(description = "Unique conversation identifier", example = "123e4567-e89b-12d3-a456-426614174000")
        @NotBlank
        String conversationId,

        @Schema(description = "Conversation title", example = "Discussion about AI")
        @NotBlank
        String title,

        @Schema(description = "Optional conversation description", example = "A detailed conversation about artificial intelligence")
        String description,

        @Schema(description = "Conversation status", example = "ACTIVE")
        @NotBlank
        String status,

        @Schema(description = "Conversation creation timestamp")
        @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", timezone = "UTC")
        @NotNull
        Instant createdAt,

        @Schema(description = "List of messages in the conversation")
        @NotNull
        List<ConversationMessageDto> messages,

        @Schema(description = "Total number of messages", example = "5")
        int messageCount
) {

    public ConversationDto {
        if (messages == null) {
            messages = List.of();
        }
    }

    public boolean isEmpty() {
        return messages.isEmpty();
    }

    public boolean hasDescription() {
        return description != null && !description.trim().isEmpty();
    }
}
