package thyyxxk.webserver.controller.surgicalmanagement;

import org.springframework.web.bind.annotation.*;
import thyyxxk.webserver.config.exception.ExceptionEnum;
import thyyxxk.webserver.entity.ResultVo;
import thyyxxk.webserver.entity.dictionary.CodeName;
import thyyxxk.webserver.entity.surgeryarrangement.QuerySurgeryParams;
import thyyxxk.webserver.entity.surgeryarrangement.request.StatisticsInquiry;
import thyyxxk.webserver.entity.surgeryarrangement.response.SurgeryStatistics;
import thyyxxk.webserver.entity.zhuyuanyisheng.shoushu.OpRecord;
import thyyxxk.webserver.service.surgicalmanagement.SurgeryArrangementService;
import thyyxxk.webserver.utils.ResultVoUtil;

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

@RestController
@RequestMapping("/surgeryArrangement")
public class SurgeryArrangementController {
    private final SurgeryArrangementService service;

    public SurgeryArrangementController(SurgeryArrangementService service) {
        this.service = service;
    }

    @GetMapping("/getDicList")
    public ResultVo<Map<String, List<CodeName>>> getDicList() {
        return service.getDicList();
    }

    @PostMapping("/selectSurgeryArrangements")
    public ResultVo<List<OpRecord>> selectSurgeryArrangements(@RequestBody QuerySurgeryParams param) {
        return service.selectSurgeryArrangements(param);
    }

    @GetMapping("/getSurgeryRooms")
    public ResultVo<List<CodeName>> getSurgeryRooms() {
        return service.getSurgeryRooms();
    }

    @GetMapping("/updateSurgeryStatus")
    public ResultVo<String> updateSurgeryStatus(@RequestParam("recordId") Integer recordId,
                                                @RequestParam("status") String status) {
        return service.updateSurgeryStatus(recordId, status);
    }

    @GetMapping("/updateArrangement")
    public ResultVo<String> updateArrangement(@RequestParam("recordId") Integer recordId,
                                              @RequestParam("column") String column,
                                              @RequestParam("value") String value) {
        return service.updateArrangement(recordId, column, value);
    }

    @PostMapping("/notifyDoctor")
    public ResultVo<String> notifyDoctor(@RequestBody OpRecord record) {
        return service.notifyDoctor(record);
    }

    @PostMapping("/queryStatistics")
    public ResultVo<SurgeryStatistics> queryStatistics(@RequestBody StatisticsInquiry inquiry) {
        SurgeryStatistics response = service.queryStatistics(inquiry);
        if (null == response) {
            return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST);
        }
        return ResultVoUtil.success(response);
    }
}
