package thyyxxk.webserver.controller.examinations;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import thyyxxk.webserver.entity.ResultVo;
import thyyxxk.webserver.entity.examinations.adicon.AdiconInquiry;
import thyyxxk.webserver.entity.examinations.adicon.ItemMatch;
import thyyxxk.webserver.entity.examinations.adicon.ListTableItem;
import thyyxxk.webserver.entity.examinations.adicon.ReportDetail;
import thyyxxk.webserver.service.examinations.AdiconService;
import thyyxxk.webserver.utils.ResultVoUtil;

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

@RestController
@RequestMapping("/adicon")
public class AdiconController {
    private final AdiconService adiconService;

    @Autowired
    public AdiconController(AdiconService adiconService) {
        this.adiconService = adiconService;
    }

    @GetMapping("/login")
    public ResultVo<Map<String, String>> login() throws Exception {
        Map<String, String> map = new HashMap<>();
        map.put("jyKey", adiconService.login("JYK"));
        map.put("blKey", adiconService.login("BL"));
        return ResultVoUtil.success(map);
    }

    @PostMapping("/getReportList")
    public ResultVo<List<ListTableItem>> getReportList(@RequestBody AdiconInquiry inquiry) throws Exception {
        return ResultVoUtil.success(adiconService.getReportList(inquiry));
    }

    @PostMapping("/getReportItems")
    public ResultVo<List<ReportDetail>> getReportItemListByCustomerBarcode(@RequestBody AdiconInquiry inquiry) throws Exception {
        return ResultVoUtil.success(adiconService.getReportItemListByCustomerBarcode(inquiry));
    }

    @PostMapping("/setSampleDown")
    public ResultVo<String> setSampleDownFlagByCustomerBarcode(@RequestBody AdiconInquiry inquiry) throws Exception {
        return ResultVoUtil.success(adiconService.setSampleDownFlagByCustomerBarcode(inquiry));
    }

    @PostMapping("/getByteReport")
    public ResultVo<String> getByteReport(@RequestBody AdiconInquiry inquiry) throws Exception {
        return ResultVoUtil.success(adiconService.getByteReport(inquiry));
    }

    @PostMapping("/getUnMatchedList")
    public ResultVo<List<ItemMatch>> getUnMatchedList(@RequestBody List<ItemMatch> request) {
        return ResultVoUtil.success(adiconService.getUnMatchedList(request));
    }

    @GetMapping("/getZdItems")
    public ResultVo<List<ItemMatch>> getZdItems() {
        return ResultVoUtil.success(adiconService.getZdItems());
    }

    @PostMapping("/executeMatch")
    public ResultVo<List<ItemMatch>> executeMatch(@RequestBody List<ItemMatch> request) {
        return ResultVoUtil.success(adiconService.executeMatch(request));
    }

    @PostMapping("/saveToTjResult")
    public ResultVo<String> saveToTjResult(@RequestBody List<ReportDetail> request) {
        return ResultVoUtil.success(adiconService.saveToTjResult(request));
    }
}
