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

import com.unicorn.hgzero.meeting.biz.dto.MeetingDTO;
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 MeetingResponse {

    @Schema(description = "회의 ID", example = "550e8400-e29b-41d4-a716-446655440000")
    private final String meetingId;

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

    @Schema(description = "회의 시작 시간", example = "2025-01-25T14:00:00")
    private final LocalDateTime startTime;

    @Schema(description = "회의 종료 시간", example = "2025-01-25T16:00:00")
    private final LocalDateTime endTime;

    @Schema(description = "회의 목적", example = "2025년 1분기 신제품 개발 방향 수립")
    private final String purpose;

    @Schema(description = "회의 장소", example = "회의실 A")
    private final String location;

    @Schema(description = "회의 안건")
    private final String agenda;

    @Schema(description = "참석자 목록")
    private final List<ParticipantResponse> participants;

    @Schema(description = "회의 상태", example = "SCHEDULED")
    private final String status;

    @Schema(description = "회의 주최자", example = "user1")
    private final String organizer;

    @Schema(description = "생성 시간", example = "2025-01-23T10:00:00")
    private final LocalDateTime createdAt;

    @Schema(description = "수정 시간", example = "2025-01-23T10:00:00")
    private final LocalDateTime updatedAt;

    /**
     * MeetingDTO로부터 MeetingResponse 생성
     */
    public static MeetingResponse from(MeetingDTO dto) {
        return MeetingResponse.builder()
                .meetingId(dto.getMeetingId())
                .title(dto.getTitle())
                .startTime(dto.getStartTime())
                .endTime(dto.getEndTime())
                .purpose(dto.getPurpose())
                .location(dto.getLocation())
                .agenda(dto.getAgenda())
                .participants(dto.getParticipants().stream()
                        .map(ParticipantResponse::from)
                        .toList())
                .status(dto.getStatus())
                .organizer(dto.getOrganizer())
                .createdAt(dto.getCreatedAt())
                .updatedAt(dto.getUpdatedAt())
                .build();
    }

    @Getter
    @Builder
    @Schema(description = "참석자 정보")
    public static class ParticipantResponse {
        @Schema(description = "사용자 ID", example = "user1")
        private final String userId;

        @Schema(description = "이메일", example = "user1@example.com")
        private final String email;

        @Schema(description = "이름", example = "김철수")
        private final String name;

        @Schema(description = "역할", example = "ORGANIZER")
        private final String role;

        public static ParticipantResponse from(MeetingDTO.ParticipantDTO dto) {
            return ParticipantResponse.builder()
                    .userId(dto.getUserId())
                    .email(dto.getEmail())
                    .name(dto.getName())
                    .role(dto.getRole())
                    .build();
        }
    }
}