"""
UI Validation Module
"""
from pathlib import Path
from typing import Protocol, Callable
class ConfigManagerProtocol(Protocol):
"""Protocol for configuration manager to manage settings."""
output_path: Path
use_vessel: bool
use_waterline: bool
vessel_id: str
waterline_value: float
def update_output_path(self, path_str: str) -> None:
"""Update output path from string input."""
...
def toggle_vessel_mode(self) -> bool:
"""Toggle vessel mode and handle mutual exclusivity. Returns True if changed."""
...
def toggle_waterline_mode(self) -> bool:
"""Toggle waterline mode and handle mutual exclusivity. Returns True if changed."""
...
[docs]
class Validator:
def __init__(
self,
get_files_func: Callable[[], list[dict]],
config_manager: ConfigManagerProtocol,
) -> None:
self.get_files_func = get_files_func
self.config_manager = config_manager
[docs]
def validate_file_selection(self) -> bool:
"""Check if at least one file is selected."""
return bool(self.get_files_func())
[docs]
def validate_output_path(self) -> bool:
"""Check if output path is specified."""
output_path = self.config_manager.output_path
return bool(output_path and output_path != Path() and str(output_path).strip())
[docs]
def validate_mutual_exclusivity(self) -> bool:
"""Check vessel and waterline options mutual exclusivity."""
use_vessel = self.config_manager.use_vessel
use_waterline = self.config_manager.use_waterline
return not (use_vessel and use_waterline)
[docs]
def validate_vessel_configuration(self) -> bool:
"""Check vessel configuration validity."""
use_vessel = self.config_manager.use_vessel
if use_vessel:
vessel_id = self.config_manager.vessel_id
return bool(vessel_id.strip())
return True
[docs]
def validate_waterline_configuration(self) -> bool:
"""Check waterline configuration validity."""
use_waterline = self.config_manager.use_waterline
if use_waterline:
waterline_value = self.config_manager.waterline_value
return waterline_value >= 0
return True