package com.unicorn.hgzero.stt.event;

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

import java.time.LocalDateTime;

/**
 * 음성 변환 관련 이벤트 정의
 */
public class TranscriptionEvent {
    
    /**
     * 실시간 변환 세그먼트 생성 이벤트
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    public static class SegmentCreated {
        private String eventId;
        private String eventType;
        private String segmentId;
        private String recordingId;
        private String meetingId;
        private String text;
        private String speakerId;
        private String speakerName;
        private LocalDateTime timestamp;
        private Double duration;
        private Double confidence;
        private Boolean warningFlag;
        private LocalDateTime eventTime;
        
        public static SegmentCreated of(String segmentId, String recordingId, String meetingId,
                                      String text, String speakerId, String speakerName,
                                      LocalDateTime timestamp, Double duration, Double confidence, Boolean warningFlag) {
            return SegmentCreated.builder()
                    .eventId(java.util.UUID.randomUUID().toString())
                    .eventType("SegmentCreated")
                    .segmentId(segmentId)
                    .recordingId(recordingId)
                    .meetingId(meetingId)
                    .text(text)
                    .speakerId(speakerId)
                    .speakerName(speakerName)
                    .timestamp(timestamp)
                    .duration(duration)
                    .confidence(confidence)
                    .warningFlag(warningFlag)
                    .eventTime(LocalDateTime.now())
                    .build();
        }
    }
    
    /**
     * 배치 변환 완료 이벤트
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    public static class TranscriptionCompleted {
        private String eventId;
        private String eventType;
        private String transcriptId;
        private String recordingId;
        private String meetingId;
        private String fullText;
        private Integer segmentCount;
        private Integer totalDuration;
        private Double averageConfidence;
        private Integer speakerCount;
        private LocalDateTime completedAt;
        private LocalDateTime eventTime;
        
        public static TranscriptionCompleted of(String transcriptId, String recordingId, String meetingId,
                                              String fullText, Integer segmentCount, Integer totalDuration,
                                              Double averageConfidence, Integer speakerCount) {
            return TranscriptionCompleted.builder()
                    .eventId(java.util.UUID.randomUUID().toString())
                    .eventType("TranscriptionCompleted")
                    .transcriptId(transcriptId)
                    .recordingId(recordingId)
                    .meetingId(meetingId)
                    .fullText(fullText)
                    .segmentCount(segmentCount)
                    .totalDuration(totalDuration)
                    .averageConfidence(averageConfidence)
                    .speakerCount(speakerCount)
                    .completedAt(LocalDateTime.now())
                    .eventTime(LocalDateTime.now())
                    .build();
        }
    }
    
    /**
     * 저신뢰도 세그먼트 경고 이벤트
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    public static class LowConfidenceWarning {
        private String eventId;
        private String eventType;
        private String segmentId;
        private String recordingId;
        private String meetingId;
        private String text;
        private String speakerId;
        private Double confidence;
        private Double threshold;
        private LocalDateTime eventTime;
        
        public static LowConfidenceWarning of(String segmentId, String recordingId, String meetingId,
                                            String text, String speakerId, Double confidence) {
            return LowConfidenceWarning.builder()
                    .eventId(java.util.UUID.randomUUID().toString())
                    .eventType("LowConfidenceWarning")
                    .segmentId(segmentId)
                    .recordingId(recordingId)
                    .meetingId(meetingId)
                    .text(text)
                    .speakerId(speakerId)
                    .confidence(confidence)
                    .threshold(0.6)
                    .eventTime(LocalDateTime.now())
                    .build();
        }
    }
}