"""
GoldSim-MODFLOW Interface
========================
Clean interface for GoldSim External Element

Setup:
- Function: run_monthly_groundwater
- 6 inputs: pumping_rate, recharge_rate, well_row, well_col, hydraulic_k, specific_yield
- 3 outputs: northwest_head, center_head, southeast_head

Features:
- Tutorial 2 style setup (21x21 grid, confined aquifer)
- 30-day monthly simulations
- Automatic simulation detection
- Monthly persistence within simulations
"""

from responsive_interface import run_modflow_step

def run_monthly_groundwater(pumping_rate, recharge_rate, well_row, well_col, hydraulic_k, specific_yield):
    """
    GoldSim entry point for monthly groundwater simulation
    
    Args:
        pumping_rate: Well pumping rate (m³/day, positive = pumping out)
        recharge_rate: Total recharge (m³/day, distributed over domain)
        well_row: Well row location (0-20, center is 10)
        well_col: Well column location (0-20, center is 10)
        hydraulic_k: Hydraulic conductivity (m/day, typical: 10)
        specific_yield: Ignored for confined aquifer
        
    Returns:
        tuple: (northwest_head, center_head, southeast_head) in meters
    """
    
    try:
        result = run_modflow_step(
            float(pumping_rate),
            float(recharge_rate),
            int(well_row),
            int(well_col),
            float(hydraulic_k),
            float(specific_yield)
        )
        
        return result
        
    except Exception as e:
        print(f"Error in groundwater simulation: {e}")
        return (40.0, 40.0, 40.0)

# Test the interface
if __name__ == "__main__":
    print("Testing GoldSim Interface")
    print("=" * 30)
    
    test_cases = [
        (0, 0, 10, 10, 10.0, 0.18, "No pumping"),
        (500, 0, 10, 10, 10.0, 0.18, "Light pumping"),
        (1000, 0, 10, 10, 10.0, 0.18, "Moderate pumping"),
        (2000, 0, 10, 10, 10.0, 0.18, "Heavy pumping"),
    ]
    
    print("Pumping | NW Head | Center | SE Head | Description")
    print("(m³/day)|   (m)   |  (m)   |   (m)   |")
    print("-" * 50)
    
    for pump, rech, row, col, k, sy, desc in test_cases:
        nw, center, se = run_monthly_groundwater(pump, rech, row, col, k, sy)
        print(f"{pump:7.0f} | {nw:7.2f} | {center:6.2f} | {se:7.2f} | {desc}")
    
    print("\nGoldSim External Element Setup:")
    print("- Module: goldsim_interface")
    print("- Function: run_monthly_groundwater")
    print("- 6 inputs, 3 outputs")