package com.unicorn.hgzero.ai.biz.service;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.unicorn.hgzero.ai.biz.domain.RelatedMinutes;
import com.unicorn.hgzero.ai.biz.gateway.SearchGateway;
import com.unicorn.hgzero.ai.biz.usecase.RelatedTranscriptSearchUseCase;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

/**
 * 관련 회의록 검색 Service
 * RAG 기반 벡터 유사도 검색
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class RelatedTranscriptSearchService implements RelatedTranscriptSearchUseCase {

    private final SearchGateway searchGateway;
    private final ObjectMapper objectMapper;

    @Override
    public List<RelatedMinutes> findRelatedTranscripts(String meetingId, String transcriptId, int limit) {
        log.info("Searching related transcripts: meetingId={}, transcriptId={}, limit={}",
            meetingId, transcriptId, limit);

        // RAG 검색
        String searchResult = searchGateway.searchRelatedTranscripts(meetingId, transcriptId, limit);

        // TODO: JSON 파싱 및 RelatedMinutes 리스트 생성
        // 현재는 mock 데이터 반환
        return List.of(
            RelatedMinutes.builder()
                .transcriptId("aa0e8400-e29b-41d4-a716-446655440005")
                .title("프로젝트 X 주간 회의")
                .date(LocalDate.of(2025, 1, 15))
                .participants(List.of("김철수", "이영희"))
                .relevanceScore(85.5)
                .commonKeywords(List.of("MSA", "API Gateway", "Spring Boot"))
                .link("/transcripts/aa0e8400-e29b-41d4-a716-446655440005")
                .build()
        );
    }
}
