package com.zjrs.ggfw.portal.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import com.zjrs.ggfw.portal.bpo.UserBPO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 验证码控制器
 * 兼容前端默认请求路径 /api/captcha 和 /api/captcha/render
 */
@Api("验证码")
@RestController
@RequestMapping("/api/captcha")
public class CaptchaController {

    private static final Logger LOG = LoggerFactory.getLogger(CaptchaController.class);

    @Resource
    private UserBPO userBPO;

    /**
     * 获取图片验证码 (兼容 /api/captcha/render)
     */
    @ApiOperation(value = "验证身份,获取图片验证码", notes = "验证身份,获取图片验证码")
    @GetMapping("/render")
    public void createKaptcha(HttpServletRequest request, HttpServletResponse response) {
        LOG.info("CaptchaController render (path: /render)...");
        userBPO.render();
    }

    /**
     * 获取图片验证码 (兼容 /api/captcha)
     */
    @ApiOperation(value = "验证身份,获取图片验证码", notes = "验证身份,获取图片验证码")
    @GetMapping
    public void createKaptchaDefault(HttpServletRequest request, HttpServletResponse response) {
        LOG.info("CaptchaController render (default path)...");
        userBPO.render();
    }
}
