package com.fs.app.controller;

import com.fs.aiSoundReplication.VoiceCloneController;
import com.fs.app.annotation.Login;
import com.fs.common.annotation.RepeatSubmit;
import com.fs.common.core.domain.R;
import com.fs.common.utils.StringUtils;
import com.fs.course.param.FsInquiryPatientInfoUParam;
import com.fs.course.param.SendInquiryParam;
import com.fs.course.vo.FsInquiryPatientInfoListUVO;
import com.fs.his.service.IFsInquiryPatientInfoService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

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

@Api("患者问诊单接口")
@RestController
@RequestMapping(value = "/app/inquiryPatient")
public class InquiryPatientInfoController extends AppBaseController {

    @Autowired
    private IFsInquiryPatientInfoService patientInfoService;


    @Login
    @ApiOperation("患者问诊单列表")
    @GetMapping("/getList")
    public R getList(FsInquiryPatientInfoUParam param) {
        PageHelper.startPage(param.getPageNum(), param.getPageSize());
        param.setUserId(Long.parseLong(getUserId()));
        List<FsInquiryPatientInfoListUVO> fsInquiryPatientInfoListUVOS = patientInfoService.selectFsInquiryPatientInfoListUVO(param);
        PageInfo<FsInquiryPatientInfoListUVO> pageInfo = new PageInfo<>(fsInquiryPatientInfoListUVOS);
        return R.ok().put("data", pageInfo);
    }


    @ApiOperation("问诊单详情")
    @GetMapping("/getInfo")
    public R getInfo(@RequestParam("id") Long id) {
        FsInquiryPatientInfoListUVO info = patientInfoService.getInfo(id);
        return R.ok().put("data", info);
    }

    //    @Login
    @ApiOperation("患者发起问诊申请给红衫")
    @PostMapping("/sendInquiryToHS")
//    @Log日志 //todo 数据流转已存fs_inquiry_order_hs_log
    @RepeatSubmit
    @Transactional(rollbackFor = Exception.class)
    public R sendInquiryToHS(@RequestBody SendInquiryParam param) throws Exception {
        if (StringUtils.isNotEmpty(getUserId())) {
            param.setUserId(getUserId());
        }
        return R.ok(patientInfoService.sendInquiryToHS(param));
    }

    @ApiOperation("红杉问诊申请回调-周期回调（暂时只处理处方请求）")
    @PostMapping("/receiveInquiryFromHsCallbackNotification")
    public R receiveInquiryFromHsCallbackNotification(HttpServletRequest param) throws Exception {

        return R.ok(patientInfoService.receiveInquiryFromHsCallbackNotification(param));
    }

    @ApiOperation("红杉问诊咨询问诊医生获取-需自动调用")
    @PostMapping("/getDoctorScheduleFromHs")
    public R getDoctorScheduleFromHs() throws Exception {
        return R.ok().put("data", patientInfoService.getDoctorScheduleFromHs());
    }

    @ApiOperation("发起咨询后-获取诊室及跳转")
    @PostMapping("/redirectToHs")
    public R redirectToHs(@RequestBody String inquiryOrderId) throws Exception {
        return R.ok(patientInfoService.redirectToHs(inquiryOrderId));
    }

    @ApiOperation("取消问诊挂号")
    @PostMapping("/cancelInquiryToHs")
    public R cancelInquiryToHs(@RequestBody String inquiryOrderId) throws Exception {
        return R.ok(patientInfoService.cancelInquiryToHs(inquiryOrderId));
    }


//    @ApiOperation("红杉问诊申请回调-进入诊室失败")
//    @PostMapping("/recieveInquiryFromHsRedirect")
////    @Log日志 //todo
//    public R recieveInquiryFromHsRedirect(HttpServletRequest param) throws JsonProcessingException {
//        patientInfoService.updateFsInquiryPatientInfoFromHsRedirect(param);
//        return R.ok();
//    }
//    @ApiOperation("红杉问诊申请回调-接收通知-获取处方")
//    @PostMapping("/recieveInquiryFromHsDispensary")
////    @Log日志 //todo
//    public R recieveInquiryFromHsDispensary(HttpServletRequest param) throws JsonProcessingException {
//        patientInfoService.recieveInquiryFromHsDispensary(param);
//        return R.ok();
//    }
}
