package com.bonus.core.nutrition.mobile.controller;

import cn.hutool.core.text.CharSequenceUtil;
import com.bonus.common.core.web.controller.BaseController;
import com.bonus.core.common.utils.HeaderFetchUtil;
import com.bonus.core.nutrition.common.service.HealthCustMedicalReportService;
import com.bonus.core.nutrition.common.service.HealthMedicalReportTmplService;
import com.bonus.core.nutrition.common.vo.HealthCustMedicalReportVO;
import com.bonus.core.nutrition.common.vo.HealthMedicalReportTmplVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping({"/health/mobile/medicalreport"})
@Api(
   tags = {"mobile-移动端人员体检报告"}
)
public class HealthMobileMedicalReportController {
   @Autowired
   @Lazy
   private HealthCustMedicalReportService healthCustMedicalReportService;
   @Autowired
   @Lazy
   private HealthMedicalReportTmplService healthMedicalReportTmplService;

   @PostMapping({"/list-medicalreport"})
//   @RequiresGuest
   @ApiOperation("查询人员体检报告记录")
   public List<HealthCustMedicalReportVO> listMedicalReport(@RequestHeader Map<String, String> headers) {
      return this.healthCustMedicalReportService.listMedicalReport(this.getOpenidByHeaders(headers), this.getSourceTypeByHeaders(headers));
   }

   @PostMapping({"/list-template"})
//   @RequiresGuest
   @ApiOperation("查询体检报告模板")
   public List<HealthMedicalReportTmplVO> listTemplate() {
      return this.healthMedicalReportTmplService.listTemplate();
   }

   protected String getOpenidByHeaders(Map<String, String> headers) {
      return HeaderFetchUtil.getValueFromHeadersIgnoreCase(headers, "openid");
   }

   protected Integer getSourceTypeByHeaders(Map<String, String> headers) {
      String value = HeaderFetchUtil.getValueFromHeadersIgnoreCase(headers, "source-type");
      return CharSequenceUtil.isNotBlank(value) ? Integer.valueOf(value) : null;
   }
}
