package cn.novalon.gym.manage.groupcourse.util;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

import java.nio.file.Path;

import static org.junit.jupiter.api.Assertions.*;

/**
 * QRCodeUtil测试类
 */
class QRCodeUtilTest {

    @TempDir
    Path tempDir;

    @Test
    void testGenerateQRCode() {
        String content = "测试二维码内容";
        String qrCodePath = QRCodeUtil.generateQRCode(content);
        
        assertNotNull(qrCodePath, "二维码路径不应为空");
        assertTrue(qrCodePath.endsWith(".png"), "二维码文件应为PNG格式");
        assertTrue(qrCodePath.contains("D:\\Games\\exmp\\image"), "二维码应保存到指定路径");
        
        System.out.println("生成的二维码路径: " + qrCodePath);
    }

    @Test
    void testGenerateQRCodeWithCustomPath() {
        String content = "自定义路径测试";
        String customPath = tempDir.toString();
        String fileName = "test_qrcode";
        
        String qrCodePath = QRCodeUtil.generateQRCode(content, customPath, fileName);
        
        assertNotNull(qrCodePath, "二维码路径不应为空");
        assertTrue(qrCodePath.endsWith(".png"), "二维码文件应为PNG格式");
        assertTrue(qrCodePath.contains(fileName), "二维码文件名应包含指定名称");
        
        System.out.println("生成的二维码路径: " + qrCodePath);
    }

    @Test
    void testGenerateQRCodeWithJsonContent() {
        String jsonContent = "{\"id\":1,\"courseName\":\"瑜伽课\",\"coachId\":100,\"startTime\":\"2026-06-18T10:00:00\"}";
        
        String qrCodePath = QRCodeUtil.generateQRCode(jsonContent);
        
        assertNotNull(qrCodePath, "二维码路径不应为空");
        assertTrue(qrCodePath.endsWith(".png"), "二维码文件应为PNG格式");
        
        System.out.println("JSON内容二维码路径: " + qrCodePath);
    }

    @Test
    void testGenerateQRCodeAndUploadToOSS() {
        String jsonContent = "{\"id\":1,\"courseName\":\"瑜伽课\",\"coachId\":100,\"startTime\":\"2026-06-18T10:00:00\"}";
        
        String ossUrl = QRCodeUtil.generateQRCodeAndUploadToOSS(jsonContent);
        
        assertNotNull(ossUrl, "OSS访问地址不应为空");
        assertTrue(ossUrl.startsWith("https://"), "OSS访问地址应为HTTPS");
        assertTrue(ossUrl.contains("ycc-filesaver.oss-cn-beijing.aliyuncs.com"), "OSS访问地址应包含正确的域名");
        assertTrue(ossUrl.contains("/qrcode/"), "OSS访问地址应包含qrcode目录");
        assertTrue(ossUrl.endsWith(".png"), "OSS访问地址应为PNG格式");
        
        System.out.println("上传到OSS的二维码地址: " + ossUrl);
    }
}