package cn.hnthyy.thmz.controller;

import cn.hnthyy.thmz.comment.UserLoginToken;
import cn.hnthyy.thmz.enums.ClassCodeEnum;
import cn.hnthyy.thmz.service.his.MzZdWorkTimeService;
import cn.hnthyy.thmz.service.his.ZdMzClassService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

@Slf4j
@RestController
public class CommonController {
    @Autowired
    private ZdMzClassService zdMzClassService;
    @Autowired
    private MzZdWorkTimeService mzZdWorkTimeService;

    /**
     * 查询科室分类
     *
     * @return
     */
    @UserLoginToken
    @RequestMapping(value = "/listClassCode", method = {RequestMethod.GET, RequestMethod.POST})
    public Map<String, Object> listClassCode() {
        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("code", 0);
        resultMap.put("message", "查询科室分类成功");
        List<Map<String, Object>> data = new ArrayList<>();
        Arrays.stream(ClassCodeEnum.values()).forEach(classCodeEnum -> {
            Map<String, Object> temp = new HashMap<>();
            temp.put("code", classCodeEnum.code);
            temp.put("name", classCodeEnum.name);
            data.add(temp);
        });
        resultMap.put("data", data);
        return resultMap;
    }


    /**
     * 查询门诊分类码
     *
     * @return
     */
    @UserLoginToken
    @RequestMapping(value = "/getMzClass", method = {RequestMethod.GET, RequestMethod.POST})
    public Map<String, Object> getMzClass() {
        Map<String, Object> resultMap = new HashMap<>();
        try {
            resultMap.put("code", 0);
            resultMap.put("message", "查询门诊分类码成功");
            resultMap.put("data", zdMzClassService.queryAllZdMzClass());
            return resultMap;
        } catch (Exception e) {
            log.error("查询门诊分类码失败，错误信息{}", e.getMessage());
            resultMap.put("code", -1);
            resultMap.put("message", "查询门诊分类码失败");
            return resultMap;
        }
    }


    /**
     * 查询所有可以使用的门诊挂号时间区间
     *
     * @return
     */
    @UserLoginToken
    @RequestMapping(value = "/getMzWorkTime", method = {RequestMethod.GET, RequestMethod.POST})
    public Map<String, Object> getMzWorkTime() {
        Map<String, Object> resultMap = new HashMap<>();
        try {
            resultMap.put("code", 0);
            resultMap.put("message", "查询门诊挂号时间区间成功");
            resultMap.put("data", mzZdWorkTimeService.queryAllMzZdWorkTime());
            return resultMap;
        } catch (Exception e) {
            log.error("查询门诊挂号时间区间失败，错误信息{}", e.getMessage());
            resultMap.put("code", -1);
            resultMap.put("message", "查询门诊挂号时间区间失败");
            return resultMap;
        }
    }
}
