package com.dne.ems.controller;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.dne.ems.dto.PublicFeedbackRequest;
import com.dne.ems.model.Feedback;
import com.dne.ems.service.FeedbackService;

import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;

/**
 * 公共API控制器，处理无需认证的公共接口
 *
 * <p>主要功能：
 * <ul>
 *   <li>接收公众反馈提交</li>
 *   <li>处理带图片上传的表单</li>
 * </ul>
 *
 * @author DNE开发团队
 * @version 1.0
 * @since 2024
 */
@RestController
@RequestMapping("/api/public")
@RequiredArgsConstructor
public class PublicController {

    private final FeedbackService feedbackService;

    /**
     * 提交公共反馈(支持图片上传)
     *
     * <p>实现细节：
     * <ol>
     *   <li>验证反馈请求参数</li>
     *   <li>处理上传的图片文件(如果有)</li>
     *   <li>保存反馈到数据库</li>
     * </ol>
     *
     * @param request 包含反馈信息的请求体(JSON格式)
     * @param files 上传的图片文件数组(可选)
     * @return 创建成功的反馈实体
     * @throws InvalidRequestException 如果请求参数无效
     * @throws FileUploadException 如果文件上传失败
     */
    @PostMapping(value = "/feedback", consumes = "multipart/form-data")
    public ResponseEntity<Feedback> submitPublicFeedback(
            @Valid @RequestPart("feedback") PublicFeedbackRequest request,
            @RequestPart(value = "files", required = false) MultipartFile[] files) {
        // We will need to update the service method to handle files.
        // For now, let's pass null and focus on the controller signature.
        Feedback createdFeedback = feedbackService.createPublicFeedback(request, files);
        return new ResponseEntity<>(createdFeedback, HttpStatus.CREATED);
    }
} 