package thyyxxk.webserver.controller.inpatient.casefrontsheet;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import thyyxxk.webserver.config.exception.ExceptionEnum;
import thyyxxk.webserver.entity.ResultVo;
import thyyxxk.webserver.entity.casefrontsheet.CaseFrontsheetMain;
import thyyxxk.webserver.service.inpatient.casefrontsheet.CaseFrontSheetExportService;
import thyyxxk.webserver.utils.ResultVoUtil;

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<CaseFrontsheetMain>> fetchSheets(@RequestParam("month") String month) {
        List<CaseFrontsheetMain> list = service.fetchSheets(month);
        if (null == list || list.isEmpty()) {
            return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST);
        }
        return ResultVoUtil.success(list);
    }
}
