package com.unicorn.hgzero.meeting.infra.event.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

/**
 * 회의록 AI 분석 완료 이벤트
 */
@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class MinutesAnalysisCompletedEvent {

    private String eventType;     // MINUTES_ANALYSIS_COMPLETED
    private String eventId;       // 이벤트 고유 ID
    private String minutesId;     // 회의록 ID
    private String analysisId;    // 분석 결과 ID
    private String status;        // COMPLETED, FAILED
    private String requesterId;   // 요청자 ID
    private LocalDateTime completedAt; // 완료 시간
    private LocalDateTime timestamp;   // 이벤트 발생 시간

    // 분석 결과 (성공 시)
    private AnalysisResult result;

    // 실패 정보 (실패 시)  
    private FailureInfo failure;

    @Getter
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    public static class AnalysisResult {
        private String[] keyPoints;      // 핵심내용
        private String[] keywords;       // 키워드
        private String summary;          // 요약
        private String[] decisions;      // 결정사항
        private String[] relatedMinutesIds; // 관련회의록 ID
        private int qualityScore;        // 분석 품질 점수 (0-100)
    }

    @Getter
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    public static class FailureInfo {
        private String errorCode;
        private String errorMessage;
        private String cause;
        private boolean retryable;
    }

    public static MinutesAnalysisCompletedEvent createSuccess(String minutesId, String analysisId, 
                                                            String requesterId, AnalysisResult result) {
        return MinutesAnalysisCompletedEvent.builder()
                .eventType("MINUTES_ANALYSIS_COMPLETED")
                .eventId("analysis-completed-" + minutesId + "-" + System.currentTimeMillis())
                .minutesId(minutesId)
                .analysisId(analysisId)
                .status("COMPLETED")
                .requesterId(requesterId)
                .completedAt(LocalDateTime.now())
                .timestamp(LocalDateTime.now())
                .result(result)
                .build();
    }

    public static MinutesAnalysisCompletedEvent createFailure(String minutesId, String analysisId,
                                                            String requesterId, FailureInfo failure) {
        return MinutesAnalysisCompletedEvent.builder()
                .eventType("MINUTES_ANALYSIS_COMPLETED")
                .eventId("analysis-failed-" + minutesId + "-" + System.currentTimeMillis())
                .minutesId(minutesId)
                .analysisId(analysisId)
                .status("FAILED")
                .requesterId(requesterId)
                .completedAt(LocalDateTime.now())
                .timestamp(LocalDateTime.now())
                .failure(failure)
                .build();
    }
}