package thyyxxk.webserver.controller.ca;

import cn.hutool.json.JSONObject;
import lombok.RequiredArgsConstructor;
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.ca.CaReturn;
import thyyxxk.webserver.entity.ca.CaSignClass;
import thyyxxk.webserver.entity.ca.CaSingBizSnReturnData;
import thyyxxk.webserver.entity.ca.PatientIdCardType;
import thyyxxk.webserver.service.ca.CaServer;
import thyyxxk.webserver.utils.ResultVoUtil;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/casign")
@RequiredArgsConstructor
public class CaController {
    private final CaServer server;

    @PostMapping("/sendBatchByCode")
    public ResultVo<List<CaReturn.CaData>> sendBatchByCode(@RequestBody CaSignClass.Send send) {
        return ResultVoUtil.success(server.sendBatchByCode(send));
    }

    @PostMapping("/sendByCode")
    public ResultVo<CaReturn.CaData> sendByCode(@RequestBody CaSignClass.Send send) {
        return ResultVoUtil.success(server.sendByCode(send));
    }

    @GetMapping("/getSignInfoByBizSn")
    public ResultVo<CaSingBizSnReturnData> getSignInfoByBizSn(@RequestParam("bizSn") String bizSn) {
        return server.getSignInfoByBizSn(bizSn);
    }

    @PostMapping("/sendMoreEventSign")
    public ResultVo<JSONObject> sendMoreEventSign(@RequestBody CaSignClass.MoreEventSign moreEventSign) {
        return server.sendMoreEventSign(moreEventSign);
    }

    @PostMapping("/h5EventSign")
    public ResultVo<CaSignClass.H5Return> h5EventSign(@RequestBody CaSignClass.H5EventSign value) {
        return server.h5EventSign(value);
    }

    @PostMapping("/emrH5EventSign")
    public ResultVo<CaSignClass.H5Return> emrH5EventSign(@RequestBody CaSignClass.H5EventSign value) {
        return server.h5EventSign(value);
    }

    @PostMapping("/hBoardSignV2")
    public ResultVo<CaSignClass.H5Return> hBoardSignV2(@RequestBody CaSignClass.H5EventSign value) {
        return server.hBoardSignV2(value);
    }

    @GetMapping("/downloadSealV2")
    public ResultVo<JSONObject> downloadSealV2(@RequestParam("id") String id,
                                               @RequestParam("documentId") String documentId) {
        return server.downloadSealV2(id, documentId);
    }

    @GetMapping("/scanCodeVerification")
    public ResultVo<Boolean> scanCodeVerification(@RequestParam("id") String id,
                                                  @RequestParam("documentId") String documentId,
                                                  @RequestParam("uuid") String uuid) {
        return server.scanCodeVerification(id, documentId, uuid);
    }

    @GetMapping("/completeQrCode")
    @PassToken
    public ResultVo<String> completeQrCode(@RequestParam("documentId") String documentId) {
        server.completeQrCode(documentId);
        return ResultVoUtil.success();
    }

    @RequestMapping("/hBoardSignReturnUrl/{type}/{document}")
    @PassToken
    public JSONObject hBoardSignReturnUrl(@PathVariable("type") String type,
                                          @PathVariable("document") String document,
                                          @RequestBody(required = false) JSONObject data) {
        if (CaServer.CaReturnEnum.zy.toString().equals(type)) {
            return server.hBoardSignReturnUrl(document, data);
        } else if (CaServer.CaReturnEnum.mz.toString().equals(type)) {
            return server.mzBoardSignReturnUrl(document, data);
        }
        return server.R(-1, "类型不存在");
    }

    @GetMapping("/getIdCardTypeList")
    public ResultVo<List<PatientIdCardType>> getIdCardTypeList(@RequestParam("patNo") String patNo) {
        return server.getIdCardTypeList(patNo);
    }

    @PostMapping("/savePatientIdCardType")
    public ResultVo<String> savePatientIdCardType(@RequestBody CaServer.SavePatientIdCardType data) {
        return server.savePatientIdCardType(data);
    }

    @GetMapping("/deletePatientIdCardType")
    public ResultVo<String> deletePatientIdCardType(@RequestParam("id") String id) {
        return server.deletePatientIdCardType(id);
    }

    @GetMapping("/sendMedicalRecordsToTablet")
    public ResultVo<String> sendMedicalRecordsToTablet(@RequestParam("id") String id) {
        return server.sendMedicalRecordsToTablet(id);
    }

}
