"""
MikoshiLang Extended Functions - Set 34
Hydrology, water resources, and oceanography
"""
import sympy as sp
from sympy import symbols, sqrt, exp, log, pi, sin, cos, atan2

def get_rules():
    """Extended set 34: Hydrology and oceanography (150 functions)"""
    x, y, t = symbols('x y t')
    
    return [
        # ===== SURFACE HYDROLOGY (40 functions) =====
        ('RainfallIntensity[depth_, duration_]', lambda d, dur: d/dur),
        ('RainfallRunoffCoefficient[C_]', lambda C: C),
        ('RationalMethod[C_, I_, A_]', lambda C, I, A: C*I*A),
        ('TimeOfConcentration[L_, S_]', lambda L, S: 0.0195*L**0.77*S**(-0.385)),
        ('KirpichFormula[L_, S_]', lambda L, S: 0.0078*L**0.77*S**(-0.385)),
        ('ManningEquation[n_, R_, S_]', lambda n, R, S: (1/n)*R**(2/3)*S**(1/2)),
        ('ManningRoughness[n_]', lambda n: n),
        ('HydraulicRadius[A_, P_]', lambda A, P: A/P),
        ('WettedPerimeter[channel_]', lambda ch: sp.Symbol('P')),
        ('FlowVelocity[Q_, A_]', lambda Q, A: Q/A),
        ('CriticalDepth[q_, g_]', lambda q, g: (q**2/g)**(1/3)),
        ('FroudeNumber[v_, g_, y_]', lambda v, g, y: v/sqrt(g*y)),
        ('SpecificEnergy[y_, v_, g_]', lambda y, v, g: y + v**2/(2*g)),
        ('HydraulicJump[y1_, Fr1_]', lambda y1, Fr1: y1/2*(-1 + sqrt(1 + 8*Fr1**2))),
        ('SubcriticalFlow[Fr_]', lambda Fr: Fr < 1),
        ('SupercriticalFlow[Fr_]', lambda Fr: Fr > 1),
        ('UniformFlow[n_, R_, S_]', lambda n, R, S: (1/n)*R**(2/3)*S**(1/2)),
        ('GraduallyVariedFlow[dy_dx_]', lambda dydx: dydx),
        ('RapidlyVariedFlow[hydraulic_jump_]', lambda hj: hj),
        ('WeirFlow[C_, L_, H_]', lambda C, L, H: C*L*H**(3/2)),
        ('BroadCrestedWeir[L_, H_]', lambda L, H: 1.7*L*H**(3/2)),
        ('SharpCrestedWeir[L_, H_]', lambda L, H: 1.84*L*H**(3/2)),
        ('OrificeFlow[C_, A_, H_]', lambda C, A, H: C*A*sqrt(2*sp.Symbol('g')*H)),
        ('SluiceGateFlow[a_, y1_]', lambda a, y1: sp.Symbol('Q')),
        ('CulvertFlow[n_, A_, R_, S_, L_]', lambda n, A, R, S, L: A*(1/n)*R**(2/3)*S**(1/2)),
        ('PipeFlow[D_, L_, hf_, f_]', lambda D, L, hf, f: sqrt(2*sp.Symbol('g')*D*hf/(f*L))),
        ('DarcyWeisbachEquation[f_, L_, D_, v_, g_]', lambda f, L, D, v, g: f*L*v**2/(D*2*g)),
        ('HazenWilliamsEquation[C_, R_, S_]', lambda C, R, S: 0.85*C*R**0.63*S**0.54),
        ('ColebrookWhiteEquation[Re_, epsilon_, D_]', lambda Re, eps, D: sp.Symbol('f')),
        ('MinorLosses[K_, v_, g_]', lambda K, v, g: K*v**2/(2*g)),
        ('TotalHeadLoss[hf_, hm_]', lambda hf, hm: hf + hm),
        ('PressureHead[P_, gamma_]', lambda P, gamma: P/gamma),
        ('VelocityHead[v_, g_]', lambda v, g: v**2/(2*g)),
        ('ElevationHead[z_]', lambda z: z),
        ('BernoulliEquation[P1_, v1_, z1_, P2_, v2_, z2_]', lambda P1, v1, z1, P2, v2, z2: P1/sp.Symbol('gamma') + v1**2/(2*sp.Symbol('g')) + z1),
        ('WaterHammer[v_, a_, t_]', lambda v, a, t: sp.Symbol('rho')*a*v),
        ('SurgeVelocity[K_, rho_]', lambda K, rho: sqrt(K/rho)),
        ('UnsteadyFlow[dQ_dt_]', lambda dQdt: dQdt),
        ('FloodRouting[I_, O_, S_]', lambda I, O, S: I - O),
        ('MuskingumMethod[K_, X_]', lambda K, X: (K, X)),
        
        # ===== GROUNDWATER HYDROLOGY (35 functions) =====
        ('DarcyLawGroundwater[K_, dh_dl_]', lambda K, dhdl: -K*dhdl),
        ('HydraulicConductivity[K_]', lambda K: K),
        ('Transmissivity[K_, b_]', lambda K, b: K*b),
        ('StorageCoefficient[S_]', lambda S: S),
        ('SpecificYield[Sy_]', lambda Sy: Sy),
        ('SpecificStorage[Ss_]', lambda Ss: Ss),
        ('Porosity[Vv_, Vt_]', lambda Vv, Vt: Vv/Vt),
        ('EffectivePorosity[ne_]', lambda ne: ne),
        ('SeepageVelocity[q_, ne_]', lambda q, ne: q/ne),
        ('DarcyVelocity[q_]', lambda q: q),
        ('PiezometricHead[P_, z_]', lambda P, z: P/sp.Symbol('gamma') + z),
        ('WaterTableElevation[h_]', lambda h: h),
        ('ConfinedAquifer[T_, S_]', lambda T, S: (T, S)),
        ('UnconfinedAquifer[K_, h_]', lambda K, h: (K, h)),
        ('TheisEquation[Q_, T_, S_, r_, t_]', lambda Q, T, S, r, t: Q/(4*pi*T)*sp.Symbol('W(u)')),
        ('TheisWellFunction[u_]', lambda u: sp.Symbol('W(u)')),
        ('CooperJacobApproximation[Q_, T_, S_, r_, t_]', lambda Q, T, S, r, t: Q/(4*pi*T)*log(2.25*T*t/(r**2*S))),
        ('DrawdownWell[s_]', lambda s: s),
        ('ConeOfDepression[r_, s_]', lambda r, s: (r, s)),
        ('RadiusOfInfluence[R_]', lambda R: R),
        ('SteadyStateFlow[Q_, T_, h1_, h2_, r1_, r2_]', lambda Q, T, h1, h2, r1, r2: Q - 2*pi*T*(h1 - h2)/log(r2/r1)),
        ('UnsteadyFlow[dh_dt_]', lambda dhdt: dhdt),
        ('AquiferTest[drawdown_, time_]', lambda s, t: (s, t)),
        ('RecoveryTest[s_residual_, t_]', lambda s, t: s),
        ('SlugTest[H0_, t_, r_]', lambda H0, t, r: H0*exp(-sp.Symbol('alpha')*t)),
        ('PumpingTest[Q_, s_, r_]', lambda Q, s, r: (Q, s, r)),
        ('WellEfficiency[theoretical_, actual_]', lambda th, act: act/th*100),
        ('WellLoss[A_, B_, Q_]', lambda A, B, Q: A*Q + B*Q**2),
        ('SpecificCapacity[Q_, s_]', lambda Q, s: Q/s),
        ('LeakyAquifer[T_, S_, K_prime_, b_prime_]', lambda T, S, Kp, bp: (T, S, Kp/bp)),
        ('LeakanceCoefficient[K_prime_, b_prime_]', lambda Kp, bp: Kp/bp),
        ('AquiferRecharge[R_]', lambda R: R),
        ('GroundwaterRecharge[P_, ET_, RO_]', lambda P, ET, RO: P - ET - RO),
        ('BaseFlow[Q_total_, Q_surface_]', lambda Qtot, Qsurf: Qtot - Qsurf),
        ('GroundwaterDischarge[Q_]', lambda Q: Q),
        
        # ===== WATERSHED HYDROLOGY (25 functions) =====
        ('WatershedArea[A_]', lambda A: A),
        ('BasinLength[L_]', lambda L: L),
        ('BasinSlope[delta_H_, L_]', lambda dH, L: dH/L),
        ('DrainageDensity[total_length_, area_]', lambda L, A: L/A),
        ('StreamOrder[order_]', lambda o: o),
        ('BifurcationRatio[Nu_, Nu_plus_1_]', lambda Nu, Nup1: Nu/Nup1),
        ('LengthRatio[Lu_plus_1_, Lu_]', lambda Lup1, Lu: Lup1/Lu),
        ('AreaRatio[Au_plus_1_, Au_]', lambda Aup1, Au: Aup1/Au),
        ('FormFactor[A_, L_]', lambda A, L: A/L**2),
        ('CircularityRatio[A_, P_]', lambda A, P: 4*pi*A/P**2),
        ('ElongationRatio[diameter_, L_]', lambda d, L: d/L),
        ('CompactnessCoefficient[P_, A_]', lambda P, A: P/(2*sqrt(pi*A))),
        ('ShapeFactor[L_, W_]', lambda L, W: L/W),
        ('CurveNumber[CN_]', lambda CN: CN),
        ('SCSRunoffEquation[P_, CN_]', lambda P, CN: (P - 0.2*(25400/CN - 254))**2/(P + 0.8*(25400/CN - 254))),
        ('InitialAbstraction[S_]', lambda S: 0.2*S),
        ('PotentialMaxRetention[CN_]', lambda CN: 25400/CN - 254),
        ('InfiltrationCapacity[f_]', lambda f: f),
        ('HortonEquation[f0_, fc_, k_, t_]', lambda f0, fc, k, t: fc + (f0 - fc)*exp(-k*t)),
        ('GreenAmptInfiltration[K_, psi_, theta_]', lambda K, psi, theta: K*(1 + psi*theta/sp.Symbol('F'))),
        ('PhilipInfiltration[S_, A_, t_]', lambda S, A, t: S*sqrt(t) + A*t),
        ('CumulativeInfiltration[F_]', lambda F: F),
        ('InfiltrationRate[f_]', lambda f: f),
        ('ExcessRainfall[P_, f_]', lambda P, f: max(0, P - f)),
        ('EffectiveRainfall[P_, losses_]', lambda P, losses: P - losses),
        
        # ===== OCEANOGRAPHY (30 functions) =====
        ('WaveHeight[H_]', lambda H: H),
        ('WavePeriod[T_]', lambda T: T),
        ('WaveLength[L_]', lambda L: L),
        ('DeepWaterWaveSpeed[g_, L_]', lambda g, L: sqrt(g*L/(2*pi))),
        ('ShallowWaterWaveSpeed[g_, h_]', lambda g, h: sqrt(g*h)),
        ('WaveDispersionRelation[omega_, k_, g_, h_]', lambda omega, k, g, h: omega**2 - g*k*sp.tanh(k*h)),
        ('WaveNumber[k_]', lambda k: k),
        ('AngularFrequency[omega_]', lambda omega: omega),
        ('GroupVelocity[c_, n_]', lambda c, n: c*n),
        ('PhaseVelocity[omega_, k_]', lambda omega, k: omega/k),
        ('WaveEnergy[rho_, g_, H_]', lambda rho, g, H: rho*g*H**2/8),
        ('WavePower[E_, cg_]', lambda E, cg: E*cg),
        ('SignificantWaveHeight[Hs_]', lambda Hs: Hs),
        ('WaveSpectrum[S_, f_]', lambda S, f: S),
        ('PiersonMoskowitzSpectrum[alpha_, g_, U_, f_]', lambda alpha, g, U, f: alpha*g**2/((2*pi)**4*f**5)*exp(-1.25*(g/(2*pi*U*f))**4)),
        ('JONSWAPSpectrum[fp_, gamma_]', lambda fp, gamma: sp.Symbol('S')),
        ('TidalRange[high_, low_]', lambda h, l: h - l),
        ('TidalCurrent[U_]', lambda U: U),
        ('TidalPrism[A_, tidal_range_]', lambda A, R: A*R),
        ('TidalConstituent[M2_, S2_, K1_, O1_]', lambda M2, S2, K1, O1: M2 + S2 + K1 + O1),
        ('HarmonicAnalysis[constituents_]', lambda c: c),
        ('StokesDrift[a_, k_, omega_]', lambda a, k, omega: omega*k*a**2),
        ('EkmanTransport[tau_, f_, rho_]', lambda tau, f, rho: tau/(f*rho)),
        ('EkmanDepth[nu_, f_]', lambda nu, f: sqrt(2*nu/f)),
        ('GeostrophicCurrent[dP_dx_, f_, rho_]', lambda dPdx, f, rho: -dPdx/(f*rho)),
        ('CoriolisParameter[phi_]', lambda phi: 2*sp.Symbol('Omega')*sin(phi)),
        ('RossbyNumber[U_, L_, f_]', lambda U, L, f: U/(f*L)),
        ('EkmanNumber[nu_, f_, D_]', lambda nu, f, D: nu/(f*D**2)),
        ('StratificationParameter[N_, f_]', lambda N, f: N/f),
        ('BruntVaisalaFrequency[g_, rho_, drho_dz_]', lambda g, rho, drhodz: sqrt(-g/rho*drhodz)),
        
        # ===== COASTAL ENGINEERING (20 functions) =====
        ('BreakingWaveHeight[Hb_]', lambda Hb: Hb),
        ('BreakingDepth[Hb_, gamma_]', lambda Hb, gamma: Hb/gamma),
        ('WaveSetup[eta_]', lambda eta: eta),
        ('WaveRunup[R_]', lambda R: R),
        ('SwashZone[R_]', lambda R: R),
        ('SurfZone[width_]', lambda w: w),
        ('LittoralDrift[Q_]', lambda Q: Q),
        ('LongshoreCurrentVelocity[V_]', lambda V: V),
        ('BeachProfile[slope_]', lambda m: m),
        ('DuneErosion[volume_]', lambda V: V),
        ('CoastalFlooding[surge_]', lambda s: s),
        ('StormSurge[wind_, pressure_]', lambda w, p: sp.Symbol('surge')),
        ('TsunamiWaveSpeed[g_, h_]', lambda g, h: sqrt(g*h)),
        ('ReflectionCoefficient[Kr_]', lambda Kr: Kr),
        ('TransmissionCoefficient[Kt_]', lambda Kt: Kt),
        ('DiffractionCoefficient[Kd_]', lambda Kd: Kd),
        ('RefractionCoefficient[Ks_]', lambda Ks: Ks),
        ('ShorelineChange[delta_x_]', lambda dx: dx),
        ('SedimentTransportRate[Q_]', lambda Q: Q),
        ('BeachNourishment[volume_]', lambda V: V),
    ]

def register():
    """Register all extended34 rules"""
    from .extended_helper import convert_rules
    return convert_rules(get_rules())
