package com.unicorn.hgzero.stt.event;

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

import java.time.LocalDateTime;

/**
 * 화자 관련 이벤트 정의
 */
public class SpeakerEvent {
    
    /**
     * 신규 화자 식별 이벤트
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    public static class NewSpeakerIdentified {
        private String eventId;
        private String eventType;
        private String speakerId;
        private String speakerName;
        private String profileId;
        private String recordingId;
        private String meetingId;
        private Double confidence;
        private LocalDateTime firstAppeared;
        private LocalDateTime eventTime;
        
        public static NewSpeakerIdentified of(String speakerId, String speakerName, String profileId,
                                            String recordingId, String meetingId, Double confidence) {
            return NewSpeakerIdentified.builder()
                    .eventId(java.util.UUID.randomUUID().toString())
                    .eventType("NewSpeakerIdentified")
                    .speakerId(speakerId)
                    .speakerName(speakerName)
                    .profileId(profileId)
                    .recordingId(recordingId)
                    .meetingId(meetingId)
                    .confidence(confidence)
                    .firstAppeared(LocalDateTime.now())
                    .eventTime(LocalDateTime.now())
                    .build();
        }
    }
    
    /**
     * 화자 정보 업데이트 이벤트
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    public static class SpeakerUpdated {
        private String eventId;
        private String eventType;
        private String speakerId;
        private String oldSpeakerName;
        private String newSpeakerName;
        private String oldUserId;
        private String newUserId;
        private String updatedBy;
        private LocalDateTime eventTime;
        
        public static SpeakerUpdated of(String speakerId, String oldSpeakerName, String newSpeakerName,
                                      String oldUserId, String newUserId, String updatedBy) {
            return SpeakerUpdated.builder()
                    .eventId(java.util.UUID.randomUUID().toString())
                    .eventType("SpeakerUpdated")
                    .speakerId(speakerId)
                    .oldSpeakerName(oldSpeakerName)
                    .newSpeakerName(newSpeakerName)
                    .oldUserId(oldUserId)
                    .newUserId(newUserId)
                    .updatedBy(updatedBy)
                    .eventTime(LocalDateTime.now())
                    .build();
        }
    }
    
    /**
     * 화자 통계 업데이트 이벤트
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    public static class SpeakerStatisticsUpdated {
        private String eventId;
        private String eventType;
        private String speakerId;
        private String recordingId;
        private String meetingId;
        private Integer totalSegments;
        private Integer totalDuration;
        private Double averageConfidence;
        private LocalDateTime lastAppeared;
        private LocalDateTime eventTime;
        
        public static SpeakerStatisticsUpdated of(String speakerId, String recordingId, String meetingId,
                                                Integer totalSegments, Integer totalDuration, Double averageConfidence) {
            return SpeakerStatisticsUpdated.builder()
                    .eventId(java.util.UUID.randomUUID().toString())
                    .eventType("SpeakerStatisticsUpdated")
                    .speakerId(speakerId)
                    .recordingId(recordingId)
                    .meetingId(meetingId)
                    .totalSegments(totalSegments)
                    .totalDuration(totalDuration)
                    .averageConfidence(averageConfidence)
                    .lastAppeared(LocalDateTime.now())
                    .eventTime(LocalDateTime.now())
                    .build();
        }
    }
}