"""
Module: src.ingestion.validator
Workorder: WO01
Purpose: Audio input validation for supported file formats.

Dependencies:
    - pathlib: File path handling

Inputs:
    - file_path: Candidate audio file path

Outputs:
    - Validation result for file existence and extension support

Key Functions/Classes:
    - validate_audio_file: Validates input file constraints

Tests: tests/unit/test_placeholder.py
"""
from pathlib import Path

from src.shared.errors import ProcessingError

SUPPORTED_AUDIO_EXTENSIONS = {".wav", ".mp3", ".m4a"}


def validate_audio_file(file_path: Path) -> bool:
    """Validate input audio file for WO01 pipeline.

    Args:
        file_path: Path to audio file.

    Returns:
        True when file exists and extension is supported.

    Raises:
        ProcessingError: If file does not exist, is not a file, or extension is unsupported.
    """
    if not file_path.exists():
        raise ProcessingError(f"Input file does not exist: {file_path}")

    if not file_path.is_file():
        raise ProcessingError(f"Input path is not a file: {file_path}")

    if file_path.suffix.lower() not in SUPPORTED_AUDIO_EXTENSIONS:
        allowed = ", ".join(sorted(SUPPORTED_AUDIO_EXTENSIONS))
        raise ProcessingError(
            f"Unsupported audio extension '{file_path.suffix}'. Allowed: {allowed}"
        )

    return True
