#!/usr/bin/env python3
"""
Input Validators
输入验证器
"""

from pathlib import Path
from typing import List, Set

from ..types import DetectorType, OutputFormat


class InputValidator:
    """输入验证器"""
    
    def __init__(self, supported_formats: Set[str]):
        self.supported_formats = supported_formats
    
    def validate_video_path(self, video_path: Path) -> List[str]:
        """验证视频路径"""
        errors = []
        
        if not video_path.exists():
            errors.append(f"视频文件不存在: {video_path}")
        
        if video_path.suffix.lower() not in self.supported_formats:
            errors.append(f"不支持的文件格式: {video_path.suffix}")
        
        return errors
    
    def validate_detector_type(self, detector_type: str) -> List[str]:
        """验证检测器类型"""
        errors = []
        
        try:
            DetectorType(detector_type)
        except ValueError:
            valid_types = [dt.value for dt in DetectorType]
            errors.append(f"无效的检测器类型: {detector_type}，支持的类型: {valid_types}")
        
        return errors
    
    def validate_threshold(self, threshold: float) -> List[str]:
        """验证阈值"""
        errors = []
        
        if not (0 <= threshold <= 100):
            errors.append(f"阈值超出范围 (0-100): {threshold}")
        
        return errors
    
    def validate_min_scene_length(self, min_scene_length: float) -> List[str]:
        """验证最小场景长度"""
        errors = []
        
        if min_scene_length < 0:
            errors.append(f"最小场景长度不能为负数: {min_scene_length}")
        
        return errors
    
    def validate_output_format(self, output_format: str) -> List[str]:
        """验证输出格式"""
        errors = []
        
        try:
            OutputFormat(output_format)
        except ValueError:
            valid_formats = [of.value for of in OutputFormat]
            errors.append(f"无效的输出格式: {output_format}，支持的格式: {valid_formats}")
        
        return errors
    
    def validate_all(self, video_path: Path, detector_type: str, threshold: float,
                    min_scene_length: float, output_format: str) -> List[str]:
        """验证所有输入参数"""
        errors = []
        
        errors.extend(self.validate_video_path(video_path))
        errors.extend(self.validate_detector_type(detector_type))
        errors.extend(self.validate_threshold(threshold))
        errors.extend(self.validate_min_scene_length(min_scene_length))
        errors.extend(self.validate_output_format(output_format))
        
        return errors
