package com.multictrl.modules.business.controller;

import com.multictrl.common.exception.ErrorCode;
import com.multictrl.common.utils.Result;
import com.multictrl.modules.business.service.MinioService;
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;

/**
 * minio对象存储
 *
 * @author Sdy
 * @since 1.0.0 2026/4/16
 */
@Tag(name = "媒体文件存储")
@RestController
@RequestMapping("/oss")
@RequiredArgsConstructor
public class MinioController {
    private final MinioService minioService;


    @Operation(summary = "上传航线媒体照片")
    @PostMapping("/uploadRouteImg/{dockSn}")
    public Result<String> uploadRouteImg(@PathVariable String dockSn,
                                         @RequestParam("file") MultipartFile file) {
        if (file.isEmpty()) {
            return new Result<String>().error(ErrorCode.UPLOAD_FILE_EMPTY);
        }

        return new Result<String>().ok(minioService.uploadRouteImg(dockSn, file));
    }

    @Operation(summary = "上传喊话器音频文件")
    @PostMapping("/uploadSpeakerAudio/{dockSn}")
    public Result<String> uploadSpeakerAudio(@PathVariable String dockSn,
                                             @RequestParam("file") MultipartFile file) {
        if (file.isEmpty()) {
            return new Result<String>().error(ErrorCode.UPLOAD_FILE_EMPTY);
        }

        return new Result<String>().ok(minioService.uploadSpeakerAudio(dockSn, file));
    }

    @Operation(summary = "上传地图标注文件")
    @PostMapping("/uploadGeoMark/{dockSn}")
    public Result<String> uploadGeoMark(@PathVariable String dockSn,
                                        @RequestParam("file") MultipartFile file) {
        if (file.isEmpty()) {
            return new Result<String>().error(ErrorCode.UPLOAD_FILE_EMPTY);
        }

        return new Result<String>().ok(minioService.uploadGeoMark(dockSn, file));
    }

    @Operation(summary = "上传字典图片")
    @PostMapping("/uploadDictImage")
    public Result<String> uploadDictImage(
                                        @RequestParam("file") MultipartFile file) {
        if (file.isEmpty()) {
            return new Result<String>().error(ErrorCode.UPLOAD_FILE_EMPTY);
        }

        return new Result<String>().ok(minioService.uploadDictImage( file));
    }
}
