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

import com.unicorn.hgzero.meeting.biz.dto.MeetingEndDTO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Getter;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 회의 종료 응답 DTO
 */
@Getter
@Builder
@Schema(description = "회의 종료 응답")
public class MeetingEndResponse {

    @Schema(description = "회의 제목", example = "Q1 전략 회의")
    private final String title;

    @Schema(description = "참석자 수", example = "4")
    private final int participantCount;

    @Schema(description = "회의 시간 (분)", example = "90")
    private final int durationMinutes;

    @Schema(description = "주요 안건 수", example = "3")
    private final int agendaCount;

    @Schema(description = "Todo 생성 수", example = "5")
    private final int todoCount;

    @Schema(description = "주요 키워드")
    private final List<String> keywords;

    @Schema(description = "안건별 AI 요약")
    private final List<AgendaSummary> agendaSummaries;

    /**
     * MeetingEndDTO로부터 MeetingEndResponse 생성
     */
    public static MeetingEndResponse from(MeetingEndDTO dto) {
        return MeetingEndResponse.builder()
                .title(dto.getTitle())
                .participantCount(dto.getParticipantCount())
                .durationMinutes(dto.getDurationMinutes())
                .agendaCount(dto.getAgendaCount())
                .todoCount(dto.getTodoCount())
                .keywords(dto.getKeywords())
                .agendaSummaries(dto.getAgendaSummaries().stream()
                        .map(AgendaSummary::from)
                        .toList())
                .build();
    }

    @Getter
    @Builder
    @Schema(description = "안건 요약 정보")
    public static class AgendaSummary {
        @Schema(description = "안건 제목", example = "1. 신제품 기획 방향성")
        private final String title;

        @Schema(description = "AI 요약 (간략)", example = "타겟 고객을 20-30대로 설정, UI/UX 개선 집중")
        private final String aiSummaryShort;

        @Schema(description = "상세 내용")
        private final AgendaDetails details;

        @Schema(description = "Todo 목록")
        private final List<TodoSummary> todos;

        public static AgendaSummary from(MeetingEndDTO.AgendaSummaryDTO dto) {
            return AgendaSummary.builder()
                    .title(dto.getTitle())
                    .aiSummaryShort(dto.getAiSummaryShort())
                    .details(AgendaDetails.from(dto.getDetails()))
                    .todos(dto.getTodos().stream()
                            .map(TodoSummary::from)
                            .toList())
                    .build();
        }
    }

    @Getter
    @Builder
    @Schema(description = "안건 상세 내용")
    public static class AgendaDetails {
        @Schema(description = "논의 주제", example = "신제품의 주요 타겟 고객층을 20-30대 직장인으로 설정하고...")
        private final String discussion;

        @Schema(description = "결정 사항")
        private final List<String> decisions;

        @Schema(description = "보류 사항")
        private final List<String> pending;

        public static AgendaDetails from(MeetingEndDTO.AgendaDetailsDTO dto) {
            return AgendaDetails.builder()
                    .discussion(dto.getDiscussion())
                    .decisions(dto.getDecisions())
                    .pending(dto.getPending())
                    .build();
        }
    }

    @Getter
    @Builder
    @Schema(description = "Todo 요약 정보")
    public static class TodoSummary {
        @Schema(description = "Todo 제목", example = "시장 조사 보고서 작성")
        private final String title;

        public static TodoSummary from(MeetingEndDTO.TodoSummaryDTO dto) {
            return TodoSummary.builder()
                    .title(dto.getTitle())
                    .build();
        }
    }
}