// === FFI 桥接测试 ===
// 验证 ts-native 能正确配置 native addon DLL 并生成 addon_ 前缀的外部符号调用

import { resize, rotate, crop, filter, get_info } from "image_proc";
import { hash, encrypt, decrypt } from "crypto_accel";

// image_proc addon 测试
function testImageProc(): number {
    // resize — 调用 addon_image_proc_resize (img_resize)
    let result1 = resize(800, 600, 1024, 768);

    // rotate — 调用 addon_image_proc_rotate (img_rotate)
    let result2 = rotate(90);

    // crop — 调用 addon_image_proc_crop (img_crop)
    let result3 = crop(0, 0, 100, 100);

    // filter — 调用 addon_image_proc_filter (img_apply_filter)
    let result4 = filter("grayscale");

    // get_info — 调用 addon_image_proc_get_info (img_get_info)
    let info = get_info();

    console.log("image_proc addon: resize, rotate, crop, filter, get_info");
    return 1;
}

// crypto_accel addon 测试
function testCryptoAccel(): number {
    // hash — 调用 addon_crypto_accel_hash (accel_hash)
    let digest = hash("hello world");

    // encrypt — 调用 addon_crypto_accel_encrypt (accel_encrypt)
    let encrypted = encrypt("secret data", "key123");

    // decrypt — 调用 addon_crypto_accel_decrypt (accel_decrypt)
    let decrypted = decrypt(encrypted, "key123");

    console.log("crypto_accel addon: hash, encrypt, decrypt");
    return 1;
}

function main(): number {
    let passed = 0;

    passed += testImageProc();
    passed += testCryptoAccel();

    console.log("FFI Addon test: " + passed + "/2 groups passed");
    return passed;
}
