"""
Integration tests for HADEX framework
"""

import pytest
import numpy as np
from src.core.equation_of_state import EquationOfState
from src.core.acoustic_model import AcousticModel
from src.navigation.swarm_algorithm import SwarmNavigationEngine
from src.sensing.oxygen_flux import OxygenFlux
from src.energy.piezo_harvester import PiezoHarvester
from src.utils.validation import Validation


class TestHADEXIntegration:
    """Integration tests for complete HADEX framework"""
    
    def test_challenger_deep_simulation(self):
        """Test complete Challenger Deep simulation"""
        
        # 1. Initialize physics models
        eos = EquationOfState(temperature=1.9, salinity=34.68, depth=10911)
        acoustic = AcousticModel(temperature=1.9, salinity=34.68, depth=10911)
        
        # 2. Calculate properties
        density = eos.compute_density()
        sound_velocity = acoustic.sound_speed()
        
        # Basic sanity checks
        assert 1000 < density < 1200
        assert 1500 < sound_velocity < 1800
        
        # 3. Initialize swarm
        swarm = SwarmNavigationEngine(num_vehicles=6)
        
        # 4. Run short simulation
        results = swarm.simulate_mission(duration_hours=1, depth=10911)
        
        assert results['num_vehicles'] == 6
        assert results['rms_error'] > 0
        
        # 5. Initialize sensors
        oxygen = OxygenFlux()
        profile = oxygen.measure_profile()
        
        assert profile.penetration_depth > 0
        
        # 6. Initialize energy harvesting
        harvester = PiezoHarvester(area=10)
        stats = harvester.measure_power(duration=360)
        
        assert stats.continuous_power > 0
        
        # 7. Validate
        validation = Validation()
        
        predicted = {
            'density': density,
            'sound_velocity': sound_velocity
        }
        
        measured = {
            'density': 1048.5,
            'sound_velocity': 1663.8
        }
        
        result = validation.validate_trench(
            'Challenger Deep',
            predicted,
            measured
        )
        
        assert 'parameters' in result
