#!/usr/bin/env python3
import sys
import os
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
"""
Basic Usage Example for HADEX Framework

This example demonstrates the core functionality of HADEX:
- Pressure and density calculations
- Sound velocity modeling
- Basic navigation
"""

import numpy as np
from src.core.equation_of_state import EquationOfState
from src.core.acoustic_model import AcousticModel
from src.core.pressure_viscosity import PressureViscosity
from src.core.fluid_properties import FluidProperties


def main():
    """Run basic usage example"""
    print("=" * 60)
    print("HADEX - Basic Usage Example")
    print("=" * 60)
    
    # Example 1: Calculate properties at Challenger Deep
    print("\n1. Challenger Deep Analysis (10,911m)")
    print("-" * 40)
    
    props = FluidProperties(temperature=1.9, salinity=34.68, depth=10911)
    all_props = props.all_properties()
    
    for key, value in all_props.items():
        if isinstance(value, float):
            print(f"   {key}: {value:.2f}")
        else:
            print(f"   {key}: {value}")
    
    # Example 2: Pressure profile with depth
    print("\n2. Pressure Profile with Depth")
    print("-" * 40)
    
    depths = [0, 2000, 4000, 6000, 8000, 10000, 10911]
    eos = EquationOfState(temperature=2.0, salinity=34.7)
    
    print(f"{'Depth (m)':>10} {'Pressure (MPa)':>15} {'Density (kg/m³)':>18}")
    print("-" * 45)
    
    for depth in depths:
        eos.depth = depth
        eos.pressure = eos._depth_to_pressure(depth)
        rho = eos.compute_density()
        P = eos.pressure
        print(f"{depth:10d} {P:15.2f} {rho:18.1f}")
    
    # Example 3: Sound velocity variation
    print("\n3. Sound Velocity with Depth")
    print("-" * 40)
    
    acoustic = AcousticModel(temperature=2.0, salinity=34.7)
    
    print(f"{'Depth (m)':>10} {'Sound Velocity (m/s)':>20}")
    print("-" * 32)
    
    for depth in depths:
        acoustic.depth = depth
        c = acoustic.sound_speed()
        print(f"{depth:10d} {c:20.1f}")
    
    # Example 4: Viscosity increase
    print("\n4. Viscosity Increase with Pressure")
    print("-" * 40)
    
    visc = PressureViscosity(temperature=2.0)
    
    print(f"{'Pressure (MPa)':>15} {'Viscosity (Pa·s)':>20} {'Increase %':>12}")
    print("-" * 50)
    
    pressures = [0.1, 20, 40, 60, 80, 100, 110]
    mu0 = visc.surface_viscosity()
    
    for P in pressures:
        mu = visc.dynamic_viscosity(P)
        increase = (mu - mu0) / mu0 * 100
        print(f"{P:15.1f} {mu:20.2e} {increase:12.1f}")
    
    # Example 5: Complete fluid properties summary
    print("\n5. Complete Fluid Properties Summary")
    print("-" * 40)
    print(props.summary())
    
    print("\n" + "=" * 60)
    print("Example completed successfully!")
    print("=" * 60)


if __name__ == "__main__":
    main()
