package thyyxxk.webserver.controller.inpatient.casefrontsheet;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import thyyxxk.webserver.config.exception.ExceptionEnum;
import thyyxxk.webserver.entity.ResultVo;
import thyyxxk.webserver.entity.casefrontsheet.request.SheetOverview;
import thyyxxk.webserver.entity.casefrontsheet.tcmsheet.TcmFrontSheetMain;
import thyyxxk.webserver.service.inpatient.casefrontsheet.tcm.TcmSheetMainService;
import thyyxxk.webserver.utils.ResultVoUtil;

@RestController
@RequestMapping("/tcmFrontSheet")
public class TcmSheetController {
    private final TcmSheetMainService mainService;

    @Autowired
    public TcmSheetController(TcmSheetMainService mainService) {
        this.mainService = mainService;
    }

    @PostMapping("/getSheetInfo")
    public ResultVo<TcmFrontSheetMain> getSheetInfo(@RequestBody SheetOverview overview) {
        TcmFrontSheetMain response = mainService.getSheetInfo(overview);
        if (null == response) {
            return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST);
        }
        return ResultVoUtil.success(response);
    }

    @PostMapping("/saveTcmSheet")
    public ResultVo<String> saveTcmSheet(@RequestBody TcmFrontSheetMain sheet) {
        return ResultVoUtil.success(mainService.saveTcmSheet(sheet));
    }
}
