const Decision = require('./extension/modules/decision.js');

function runTest(testName, crop, worldEvents, expectedAction) {
    console.log(`\n--- Test: ${testName} ---`);
    console.log("Crop:", JSON.stringify(crop));
    console.log("Events:", JSON.stringify(worldEvents));

    const result = Decision.shouldHarvest(crop, worldEvents);
    console.log("Result:", JSON.stringify(result, null, 2));

    if (result.action === expectedAction) {
        console.log("PASS");
    } else {
        console.error(`FAIL: Expected ${expectedAction}, got ${result.action}`);
    }
}

// Case 1: High Value (Rainbow), no time left to wait -> Harvest Now
// Even if time left, Rainbow (50x) is huge limit. 
// If we have Rainbow, can we get more?
// Maybe Golden? 
// Let's assume Rainbow is good enough to harvest if risk is high or gain is low.
// But math will decide.
runTest("Rainbow Crop - Harvest Now expected",
    { species: "test", baseValue: 10, scale: 1, mutations: ["Rainbow"] },
    {
        Time_Until_Next_Event_Hrs: 1,
        Time_Remaining_Hrs: 0.5, // Will mature during wait
        P_Next_Rain_Thunderstorm: 0.1,
        P_Next_Frost: 0.1,
        Time_To_Next_Blood_Moon_Hrs: 10,
        Event_Active: false
    },
    "WAIT" // Math says E (1.2x) > V (1.0x), so we wait.
);

// Case 2: New Crop, Rain incoming (Chance of Wet)
runTest("New Crop - Wait for Rain",
    { species: "test", baseValue: 10, scale: 1, mutations: [] },
    {
        Time_Until_Next_Event_Hrs: 1,
        Time_Remaining_Hrs: 10,
        P_Next_Rain_Thunderstorm: 0.8, // High chance of rain
        P_Next_Frost: 0.0,
        Time_To_Next_Blood_Moon_Hrs: 10,
        Event_Active: false
    },
    "WAIT"
);

// Case 3: Wet Crop, Frost incoming (Fusion chance -> Frozen 10x)
runTest("Wet Crop - Wait for Frost (Fusion)",
    { species: "test", baseValue: 10, scale: 1, mutations: ["Wet"] }, // Val = 20
    {
        Time_Until_Next_Event_Hrs: 1,
        Time_Remaining_Hrs: 10,
        P_Next_Rain_Thunderstorm: 0.0,
        P_Next_Frost: 0.6, // Good frost chance
        Time_To_Next_Blood_Moon_Hrs: 10,
        Event_Active: false
    },
    "WAIT"
);

// Case 4: Strategic Blood Moon
runTest("Standard Crop - Wait for Blood Moon",
    { species: "test", baseValue: 10, scale: 1, mutations: [] },
    {
        Time_Until_Next_Event_Hrs: 5,
        Time_Remaining_Hrs: 20,
        P_Next_Rain_Thunderstorm: 0.1,
        P_Next_Frost: 0.1,
        Time_To_Next_Blood_Moon_Hrs: 6, // Can reach BM
        Event_Active: false
    },
    "WAIT"
);
