package thyyxxk.webserver.controller.examinations;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import thyyxxk.webserver.config.auth.PassToken;
import thyyxxk.webserver.entity.ResultVo;
import thyyxxk.webserver.entity.examinations.inspections.request.ReportDetailInquiry;
import thyyxxk.webserver.entity.examinations.inspections.request.ReportIndexInquiry;
import thyyxxk.webserver.entity.examinations.inspections.response.*;
import thyyxxk.webserver.service.examinations.InspectionsService;
import thyyxxk.webserver.utils.ResultVoUtil;

import java.util.List;

@RestController
@RequestMapping("/inspections")
public class InspectionsController {
    private final InspectionsService service;

    @Autowired
    public InspectionsController(InspectionsService service) {
        this.service = service;
    }

    @PassToken
    @PostMapping("/checkIndexByCategory")
    public ResultVo<List> checkIndexByCategory(@RequestBody ReportIndexInquiry inquiry) {
        List list;
        switch (inquiry.getReportCategory()) {
            case JC:
                list = service.checkTestIndex(inquiry);
                break;
            case BL:
                list = service.checkPathologyIndex(inquiry);
                break;
            case XD:
                list = service.checkElectroIndex(inquiry);
                break;
            default:
                list = service.queryJyIndex(inquiry);
                break;
        }
        return ResultVoUtil.success(list);
    }

    @PostMapping("/checkExamIndex")
    public ResultVo<List<JyIndexResponse>> checkExamIndex(@RequestBody ReportIndexInquiry inquiry) {
        return ResultVoUtil.success(service.queryJyIndex(inquiry));
    }

    @PassToken
    @PostMapping("/checkExamDetail")
    public ResultVo<JyDetailResponse> checkExamDetail(@RequestBody ReportDetailInquiry param) {
        return ResultVoUtil.success(service.queryJyDetail(param.getReportId()));
    }

    @PostMapping("/checkTestIndex")
    public ResultVo<List<TestReport>> checkTestIndex(@RequestBody ReportIndexInquiry inquiry) {
        return ResultVoUtil.success(service.checkTestIndex(inquiry));
    }

    @PassToken
    @PostMapping("/checkTestDetail")
    public ResultVo<TestReport> checkTestDetail(@RequestBody ReportDetailInquiry param) {
        return ResultVoUtil.success(service.checkTestDetail(param));
    }

    @PostMapping("/checkPathologyIndex")
    public ResultVo<List<PathologyIndex>> checkPathologyIndex(@RequestBody ReportIndexInquiry request) {
        request.setReqStartTime(request.getReqStartTime().replaceAll("-", ""));
        request.setReqEndTime(request.getReqEndTime().replaceAll("-", ""));
        return ResultVoUtil.success(service.checkPathologyIndex(request));
    }

    @PostMapping("/checkElectroIndex")
    public ResultVo<List<ElectroIndex>> checkElectroIndex(@RequestBody ReportIndexInquiry inquiry) {
        inquiry.setReqStartTime(inquiry.getReqStartTime().replaceAll("-", ""));
        inquiry.setReqEndTime(inquiry.getReqEndTime().replaceAll("-", ""));
        return ResultVoUtil.success(service.checkElectroIndex(inquiry));
    }
}
