package com.unicorn.hgzero.ai.infra.controller;

import com.unicorn.hgzero.ai.biz.usecase.SectionSummaryUseCase;
import com.unicorn.hgzero.ai.infra.dto.request.SectionSummaryRequest;
import com.unicorn.hgzero.ai.infra.dto.response.SectionSummaryResponse;
import com.unicorn.hgzero.common.dto.ApiResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * 섹션 AI 요약 재생성 Controller
 * POST /api/sections/{sectionId}/regenerate-summary
 */
@RestController
@RequestMapping("/api/ai/sections")
@RequiredArgsConstructor
@Slf4j
@Tag(name = "Section", description = "섹션 AI 요약 재생성 API")
public class SectionController {

    private final SectionSummaryUseCase sectionSummaryUseCase;

    @PostMapping("/{sectionId}/regenerate-summary")
    @Operation(summary = "섹션 AI 요약 재생성", description = "사용자가 작성한 섹션 내용을 기반으로 AI 요약을 재생성합니다")
    public ResponseEntity<ApiResponse<SectionSummaryResponse>> regenerateSummary(
            @PathVariable String sectionId,
            @Valid @RequestBody SectionSummaryRequest request) {

        log.info("섹션 요약 재생성 요청 - sectionId: {}, meetingId: {}", sectionId, request.getMeetingId());

        String summary = sectionSummaryUseCase.regenerateSummary(
            sectionId,
            request.getSectionContent(),
            request.getMeetingId()
        );

        SectionSummaryResponse response = SectionSummaryResponse.builder()
                .summary(summary)
                .generatedAt(LocalDateTime.now())
                .build();

        return ResponseEntity.ok(ApiResponse.success(response));
    }
}
