package thyyxxk.webserver.controller.inpatient;

import com.alibaba.fastjson.JSONArray;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import thyyxxk.webserver.config.auth.PassToken;
import thyyxxk.webserver.entity.ResultVo;
import thyyxxk.webserver.entity.inpatient.dismiss.*;
import thyyxxk.webserver.entity.inpatient.patient.Patient;
import thyyxxk.webserver.service.inpatient.DismissService;
import thyyxxk.webserver.utils.ResultVoUtil;
import thyyxxk.webserver.utils.TokenUtil;

import java.util.List;

/**
 * @author dj
 */
@Slf4j
@RestController
@RequestMapping("/dismiss")
public class DismissController {
    private final DismissService service;
    public DismissController(DismissService service) {
        this.service = service;
    }

    @PassToken
    @GetMapping("/getActOrders")
    public ResultVo<List<ActOrderGroup>> getActOrders(@RequestParam("inpatientNo") String inpatientNo,
                                                      @RequestParam("admissTimes") Integer admissTimes) {
        return service.getActOrders(inpatientNo, admissTimes);
    }

    @PassToken
    @GetMapping("/powersiPreDischarge")
    public ResultVo<JSONArray> powersiPreDischarge(@RequestParam("visitId") String visitId) {
        return service.powersiPreDischarge(visitId);
    }

    @PostMapping("/dismiss")
    public ResultVo<Object> dismiss(@RequestBody Patient param) {
        param.setStaffId(TokenUtil.getInstance().getTokenUserId());
        return service.dismiss(param);
    }

    @PostMapping("/dismissCalculate")
    public ResultVo<List<IllegalFee>> calculate(@RequestBody Patient param) {
        param.setStaffId(TokenUtil.getInstance().getTokenUserId());
        return service.calculateForDismiss(param);
    }

    @PostMapping("/selfPayDismiss")
    public synchronized ResultVo<String> selfPayDismiss(@RequestBody MedinsSettleFee param) {
        param.setStaffId(TokenUtil.getInstance().getTokenUserId());
        return ResultVoUtil.success(service.executeDischarging(param));
    }

}
