"""
Static MODFLOW Model Setup - FloPy Tutorial 2 Benchmark
========================================================
Creates the 1×10×10 grid model for the FloPy Tutorial 2 benchmark.
NO RIV or RCH packages - only GHB and WEL for Tutorial 2 compliance.
"""

import numpy as np
import flopy


def create_static_model(model_name='gspy_tutorial2', model_ws='.'):
    """
    Create static MODFLOW model for FloPy Tutorial 2 Benchmark.
    1×10×10 grid, 1000m spacing, 10.0m initial head, Sy=0.3
    """
    
    # Model dimensions (FloPy Tutorial 2 specification)
    nlay, nrow, ncol = 1, 10, 10
    delr = delc = 1000.0  # 1000m cell spacing
    top = 25.0
    botm = 0.0
    
    # Temporal discretization - single 1-day step per call
    nper = 1
    perlen = [1.0]  # 1 day
    nstp = [1]      # 1 time step
    steady = [False]  # Transient
    
    # Create MODFLOW model object
    mf = flopy.modflow.Modflow(modelname=model_name, model_ws=model_ws)
    
    # DIS package
    dis = flopy.modflow.ModflowDis(mf, nlay, nrow, ncol, delr=delr, delc=delc,
                                   top=top, botm=botm, nper=nper, 
                                   perlen=perlen, nstp=nstp, steady=steady)
    
    # BAS package - all active cells (no constant head boundaries)
    ibound = np.ones((nlay, nrow, ncol), dtype=np.int32)
    
    # Initial heads - 10.0m everywhere (will be overridden by persistent state)
    strt = np.ones((nlay, nrow, ncol), dtype=np.float32) * 10.0
    
    bas = flopy.modflow.ModflowBas(mf, ibound=ibound, strt=strt)
    
    # LPF package - FloPy Tutorial 2 parameters
    hk = 10.0     # Hydraulic conductivity (m/day) - will be overridden by input
    vka = 10.0    # Vertical hydraulic conductivity
    sy = 0.3      # Specific yield - will be overridden by input
    ss = 1e-4     # Specific storage
    
    lpf = flopy.modflow.ModflowLpf(mf, hk=hk, vka=vka, sy=sy, ss=ss, 
                                   laytyp=1, laywet=0)
    
    # OC package - save head at end of period
    spd = {(0, 0): ['print head', 'save head']}
    oc = flopy.modflow.ModflowOc(mf, stress_period_data=spd, compact=True)
    
    # PCG package
    pcg = flopy.modflow.ModflowPcg(mf)
    
    # Note: GHB and WEL packages will be added dynamically by modflow_runner.py
    # based on tutorial_period parameter
    
    return mf


if __name__ == "__main__":
    # Test static model creation
    print("Testing static MODFLOW model creation...")
    
    mf = create_static_model()
    print(f"Created model with {len(mf.packagelist)} packages:")
    for pkg in mf.packagelist:
        print(f"  - {pkg}")
    
    # Test the static model creation
    mf = create_static_model()
    print(f"Created Tutorial 2 model: {mf.nlay}×{mf.nrow}×{mf.ncol} grid")