package org.example;

import org.example.Auth.utils.SafetyUtil;
import org.example.Utils.ConfigUtil;

import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import static org.example.Utils.PublicUtil.GenerateCaptchaImage;

public class JdbcVersionChecker {
    public static void main(String[] args) {
        // 1. 生成6位验证码（复用之前的RandomCodeGenerator类）
        String code = "8K792B"; // 可替换为RandomCodeGenerator.generateRandomCode(6)
        System.out.println("验证码：" + code);

        // 2. 生成验证码图片到内存流（对应C#的MemoryStream）
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        try {
            GenerateCaptchaImage(code, stream);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

//         可选：将内存流写入文件，验证效果
        FileOutputStream fileOut = null;
        try {
            fileOut = new FileOutputStream("captcha.png");
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
        try {
            stream.writeTo(fileOut);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        try {
            fileOut.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        System.out.println("验证码图片已保存为 captcha.png");
    }
}