package com.zioinfo.cms.ugc;

import com.zioinfo.cms.common.ApiResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * UGC API — 게시판/리뷰/댓글/문의 + 모더레이션 큐.
 *
 * <p>작성(POST /public)은 공개 delivery 경로가 아니므로 Author+ 권한 필요.
 * 운영 화면용 큐/모더레이션은 Editor+ 권장(SecurityConfig POST/PUT 가드).
 */
@RestController
@RequestMapping("/api/cms/ugc")
@RequiredArgsConstructor
public class UgcController {

    private final UgcService service;

    @GetMapping
    public ApiResponse<List<CmsUgc>> list(@RequestParam(required = false) String ugcType,
                                          @RequestParam(required = false) String moderationStatus,
                                          @RequestParam(required = false) Long targetContentId) {
        return ApiResponse.ok(service.list(ugcType, moderationStatus, targetContentId));
    }

    /** 모더레이션 큐 (PENDING). */
    @GetMapping("/queue")
    public ApiResponse<List<CmsUgc>> queue() {
        return ApiResponse.ok(service.queue());
    }

    @GetMapping("/{id}")
    public ApiResponse<CmsUgc> get(@PathVariable Long id) {
        return ApiResponse.ok(service.get(id));
    }

    /** UGC 작성 (AI 모더레이션 자동). */
    @PostMapping
    public ApiResponse<CmsUgc> create(@RequestBody Map<String, Object> req) {
        return ApiResponse.ok(service.create(req));
    }

    /** 모더레이터 승인/반려. */
    @PutMapping("/{id}/moderate")
    public ApiResponse<CmsUgc> moderate(@PathVariable Long id, @RequestBody Map<String, String> req) {
        return ApiResponse.ok(service.moderate(id, req.get("status"), req.get("reason")));
    }

    /** 리뷰 AI 요약. */
    @GetMapping("/review-summary")
    public ApiResponse<Map<String, Object>> reviewSummary(@RequestParam String targetRef) {
        return ApiResponse.ok(service.reviewSummary(targetRef));
    }

    @DeleteMapping("/{id}")
    public ApiResponse<Void> delete(@PathVariable Long id) {
        service.delete(id);
        return ApiResponse.ok(null);
    }
}
