package com.reading.platform.controller;

import com.reading.platform.common.response.Result;
import com.reading.platform.dto.response.FileUploadResponse;
import com.reading.platform.service.FileUploadService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@Tag(name = "文件上传", description = "文件上传接口")
@RestController
@RequestMapping("/api/v1/files")
@RequiredArgsConstructor
public class FileUploadController {

    private final FileUploadService fileUploadService;

    @Operation(summary = "上传文件")
    @PostMapping("/upload")
    public Result<FileUploadResponse> uploadFile(@RequestParam("file") MultipartFile file) {
        String url = fileUploadService.uploadFile(file);
        return Result.success(FileUploadResponse.of(url, file.getOriginalFilename(), file.getSize()));
    }

    @Operation(summary = "删除文件")
    @DeleteMapping("/delete")
    public Result<Void> deleteFile(@RequestParam("filePath") String filePath) {
        fileUploadService.deleteFile(filePath);
        return Result.success();
    }
}
