package com.cxyxiaomo.epp.access.controller;

import com.cxyxiaomo.epp.common.pojo.User;
import com.cxyxiaomo.epp.common.response.Res;
import com.cxyxiaomo.epp.access.rpc.UserServiceFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/access/code")
public class CodeController {

    @Autowired
    private UserServiceFeign userService;

    @PostMapping("/getCodeInfo")
    @ResponseBody
    public Res getCodeInfo(@RequestParam("id") Integer id) {
        User user = userService.getUserById(id);
        if (user == null) {
            return Res.error("用户不存在");
        }

        // TODO 判断用户的健康状态（昨日是否体温打卡，管理员是否禁止该用户进出，用户所属楼栋是否允许出入等）

        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("qrcodeColor", "green");
        map.put("infoText", "绿码 请通行");
        map.put("infoTextColor", "green");
        map.put("extra", user);
        return Res.success(map);
    }
}
