package com.writeoff.module.auth.controller;

import com.writeoff.common.api.ApiResponse;
import com.writeoff.security.CaptchaService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/api/captcha")
public class CaptchaController {

    private final CaptchaService captchaService;

    public CaptchaController(CaptchaService captchaService) {
        this.captchaService = captchaService;
    }

    /**
     * 获取图形验证码。
     * 返回 captchaId + Base64 编码的 PNG 图片。
     */
    @GetMapping
    public ApiResponse<Map<String, String>> getCaptcha() {
        return ApiResponse.success(captchaService.generate());
    }
}
