# SPDX-FileCopyrightText: 2026 Yating Zhang
# SPDX-License-Identifier: MIT

println("="^60)
println("Starting Full Numerical Reproduction (Julia Only)")
println("="^60)

# --- PATH SETUP ---
const PROJECT_ROOT = @__DIR__ 
# ------------------

include(joinpath(PROJECT_ROOT, "src", "LargeM_CuttingPlane.jl")) 
include(joinpath(PROJECT_ROOT, "src", "Project_CuttingPlane.jl")) 
include(joinpath(PROJECT_ROOT, "src", "Conic_Env.jl"))  


 
# We look for "--mode" followed by "full" or the combined "--mode=full"
is_full_mode = false
for i in 1:length(ARGS)
    if ARGS[i] == "--mode" && i < length(ARGS) && ARGS[i+1] == "full"
        global is_full_mode = true
    elseif ARGS[i] == "--mode=full"
        global is_full_mode = true
    end
end 


# If full mode is active, we pass the flag; otherwise, we pass an empty list
mode_flag = is_full_mode ? ["--mode", "full"] : String[]


const scripts = [
    ("scripts/Table1_Sec4_3.jl", "Table 1 (Section 4.3)"),
    ("scripts/Table3_4_Sec6_1_CompareModel.jl", "Tables 3 & 4 (Section 6.1)"),
    ("scripts/Table5_Sec6_2_Heuristic.jl", "Table 5 (Section 6.2)"),
    ("scripts/Table6_Sec6_3_Cyclic.jl", "Table 6 (Section 6.3)"),
    ("scripts/TableEC2_ec6_1_Constraints.jl", "Table EC.2 (Section EC.6.1)"),
    ("scripts/TableEC3_ec_6_2_LargeM.jl", "Table EC.3 (Section EC.6.2)"),
    ("scripts/TableEC4_ec_6_3_CyclicRevenue.jl", "Table EC.4 (Section EC.6.3)")
]

t_start = time()


for (script_path, desc) in scripts
    println("\n" * "-"^40)
    println("Running: $desc")
    
    # Construct the command display  
    cmd_display = is_full_mode ? "julia --project=. $script_path --mode full" : "julia --project=. $script_path"
    println("Command: $cmd_display")
    println("-"^40)
    
    try  
        # If mode_flag is empty, it adds nothing to the command.
        # If mode_flag is ["--mode", "full"], it appends those arguments.
        run(`julia --project=. $script_path $mode_flag`)
        
        println("✔ Finished: $desc")
    catch e
        println("✖ Error in: $desc")
        println(e)
        exit(1)
    end
end

elapsed = (time() - t_start) / 60
println("\n" * "="^60)
println("All Numerical Experiments completed in $(round(elapsed, digits=2)) minutes.")
println("="^60)
