package com.corewing.app.modules.qc;

import com.corewing.app.common.Result;
import com.corewing.app.dto.qc.UploadTestRecordRequest;
import com.corewing.app.dto.qc.ValidateSnRequest;
import com.corewing.app.entity.QcTestRecord;
import com.corewing.app.service.QcTestService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

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

@Api(tags = "QC测试")
@RestController
@RequestMapping("/api/qc/test")
public class QcTestController {

    private final QcTestService qcTestService;

    public QcTestController(QcTestService qcTestService) {
        this.qcTestService = qcTestService;
    }

    @ApiOperation("上传测试记录")
    @PostMapping("/upload")
    public Result<String> uploadTestRecord(@RequestBody UploadTestRecordRequest request) {
        return qcTestService.uploadTestRecord(request);
    }

    @ApiOperation("上传照片")
    @PostMapping("/upload-photo")
    public Result<Map<String, String>> uploadPhoto(@RequestParam("testNo") String testNo,
                                                   @RequestParam("photo") MultipartFile photo) {
        return qcTestService.uploadPhoto(testNo, photo);
    }

    @ApiOperation("验证SN")
    @PostMapping("/validate-sn")
    public Result<Boolean> validateSn(@RequestBody ValidateSnRequest request) {
        return qcTestService.validateSn(request);
    }

    @ApiOperation("查询SN历史记录")
    @GetMapping("/history")
    public Result<List<QcTestRecord>> getHistory(@RequestParam("sn") String sn) {
        return qcTestService.getHistory(sn);
    }

    @ApiOperation("获取测试报告")
    @GetMapping("/report")
    public Result<String> getReport(@RequestParam("testNo") String testNo) {
        return qcTestService.getReport(testNo);
    }
}
