#!/usr/bin/env python3
"""
Test script for the preprocess_vox_data.py implementation.
This script demonstrates how to use the vocal preprocessing functions.
"""

import sys
import os
from pathlib import Path

# Add the scripts directory to the path so we can import the module
sys.path.append(str(Path(__file__).parent))

from preprocess_vox_data import _preprocess_vox_meta


def test_preprocessing():
    """Test the vocal preprocessing function with a sample file."""

    # Example usage - replace with actual file path
    test_file = "/path/to/your/vocal/file.opus"

    if not os.path.exists(test_file):
        print(f"Test file not found: {test_file}")
        print("Please update the test_file path to point to an actual Opus file.")
        return

    print(f"Testing vocal preprocessing with: {test_file}")

    # Test with default parameters (dry run)
    result = _preprocess_vox_meta(test_file, dry_run=True)

    # Test with custom output directory (dry run)
    print("\nTesting with custom output directory:")
    result_custom = _preprocess_vox_meta(
        test_file, dry_run=True, output_dir="/tmp/vox_test"
    )

    if result["success"]:
        print("✅ Processing successful!")
        print(f"  Input: {result['input_path']}")
        print(f"  Output: {result['output_path']}")
        print(f"  Original duration: {result['original_duration_s']:.2f}s")
        print(f"  Trimmed duration: {result['trimmed_duration_s']:.2f}s")
        print(f"  Kept spans: {len(result['kept_spans'])} regions")
        if result.get("dry_run", False):
            print("  🔍 DRY RUN - No file was written")
    else:
        print("❌ Processing failed!")
        print(f"  Error: {result['error']}")

    # Show custom directory result
    if result_custom["success"]:
        print("\n✅ Custom directory test successful!")
        print(f"  Input: {result_custom['input_path']}")
        print(f"  Output: {result_custom['output_path']}")
        print(f"  Custom dir: {result_custom.get('output_dir', 'None')}")
        if result_custom.get("dry_run", False):
            print("  🔍 DRY RUN - No file was written")
    else:
        print("\n❌ Custom directory test failed!")
        print(f"  Error: {result_custom['error']}")


if __name__ == "__main__":
    print("Vocal Preprocessing Test Script")
    print("=" * 40)

    test_preprocessing()

    print("\n" + "=" * 40)
    print("Test completed!")
    print("\nTo run the full preprocessing pipeline:")
    print("python preprocess_vox_data.py")
