package thyyxxk.webserver.controller.inpatient.casefrontsheet;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import thyyxxk.webserver.config.exception.ExceptionEnum;
import thyyxxk.webserver.entity.ResultVo;
import thyyxxk.webserver.entity.casefrontsheet.CaseFrontsheetMain;
import thyyxxk.webserver.entity.casefrontsheet.request.ExportDclRequest;
import thyyxxk.webserver.entity.casefrontsheet.request.ExportHistorySheets;
import thyyxxk.webserver.entity.casefrontsheet.response.ExportDclResponse;
import thyyxxk.webserver.entity.casefrontsheet.response.SheetForHqms;
import thyyxxk.webserver.service.inpatient.casefrontsheet.CaseFrontSheetExportService;
import thyyxxk.webserver.utils.ResultVoUtil;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/frontSheetExport")
public class FrontSheetExportController {
    private final CaseFrontSheetExportService service;

    @Autowired
    public FrontSheetExportController(CaseFrontSheetExportService service) {
        this.service = service;
    }

    @GetMapping("/fetchSheets")
    public ResultVo<List<SheetForHqms>> fetchSheets(@RequestParam("month") String month,
                                                          @RequestParam("isHqms") boolean isHqms) {
        List<SheetForHqms> list = service.fetchSheets(month, isHqms);
        if (null == list || list.isEmpty()) {
            return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST);
        }
        return ResultVoUtil.success(list);
    }

    @PostMapping("/getExportableDclData")
    public ResultVo<List<ExportDclResponse>> getExportableDclData(@RequestBody ExportDclRequest request) {
        List<ExportDclResponse> list = service.getExportableDclData(request);
        if (list.isEmpty()) {
            return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST);
        }
        return ResultVoUtil.success(list);
    }

    @PostMapping("/getHistorySheets")
    public void getHistorySheets(@RequestBody ExportHistorySheets request, HttpServletResponse response) {
        service.getHistorySheets(request, response);
    }
}
