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

import subprocess
import sys
import time
 

def run_cmd(command, step_name):
    print(f"\n{'='*50}")
    print(f"Step: {step_name}")
    print(f"Cmd : {command}")
    print(f"{'='*50}")
    
 
    if command.startswith("python"):
        command = command.replace("python", sys.executable, 1)
        
    try:
        subprocess.run(command, shell=True, check=True)
    except subprocess.CalledProcessError:
        print(f"!!! Error in step: {step_name}")
        sys.exit(1)

def main():
    print("Starting Case Study Reproduction (Hybrid Python + Julia)...")
    start = time.time()

    # 1. Estimation (Python)
    run_cmd("python scripts/Case_estimation.py", "1. Estimation (Table 2)")

    # 2. Optimization (Julia) - 
    run_cmd("julia --project=. scripts/Case_5_2_optimization.jl", "2. Optimization")

    # 3. Plotting (Python)  
    run_cmd("python scripts/Case_plot.py", "3. Plotting Figures")

    print(f"\nCase Study completed in {(time.time() - start)/60:.2f} minutes.")

if __name__ == "__main__":
    main()