#!/bin/bash
# Example validation script
# Demonstrates how to run Python processing and validate against MATLAB output

set -e  # Exit on error

# Configuration
CONTROL_UNIT="CU001"
CHAIN="A"
OUTPUT_DIR="validation_reports"
DATE=$(date +%Y-%m-%d_%H-%M-%S)

echo "========================================"
echo "Python vs MATLAB Validation Script"
echo "========================================"
echo "Control Unit: $CONTROL_UNIT"
echo "Chain: $CHAIN"
echo "Date: $DATE"
echo ""

# Create output directory
mkdir -p "$OUTPUT_DIR"

# Step 1: Run Python processing
echo "Step 1: Running Python processing..."
python -m src.main "$CONTROL_UNIT" "$CHAIN"
echo "✓ Python processing complete"
echo ""

# Step 2: Wait a moment for database commit
sleep 2

# Step 3: Run validation for all sensor types
echo "Step 2: Running validation..."
REPORT_FILE="$OUTPUT_DIR/${CONTROL_UNIT}_${CHAIN}_validation_${DATE}.txt"

python -m src.validation.cli "$CONTROL_UNIT" "$CHAIN" \
    --output "$REPORT_FILE" \
    --include-equivalent

echo "✓ Validation complete"
echo ""

# Step 4: Display summary
echo "========================================"
echo "Validation Summary"
echo "========================================"
cat "$REPORT_FILE"
echo ""

echo "Full report saved to: $REPORT_FILE"

# Check if validation passed
if grep -q "VALIDATION PASSED" "$REPORT_FILE"; then
    echo "✓✓✓ SUCCESS: Python output matches MATLAB ✓✓✓"
    exit 0
else
    echo "✗✗✗ WARNING: Validation detected differences ✗✗✗"
    echo "Please review the report above for details."
    exit 1
fi
