from pydantic import BaseModel, validator from typing import List, Optional import re class ModuleData(BaseModel): module: str class_name: str lecture: str tutorial: str @validator('lecture', 'tutorial') def validate_time_format(cls, v): if not v or v.strip() == '': return v # Temporarily relaxed validation - just check basic structure if ' to ' not in v.lower(): raise ValueError(f'Invalid time format: "{v}". Must contain "to" (e.g., "Mon 4.30pm to 6pm")') return v.strip() class SearchRequest(BaseModel): modules: List[ModuleData] num_combinations: int = 4 restrict_back_to_back: bool = False @validator('num_combinations') def validate_num_combinations(cls, v): if v < 1 or v > 20: raise ValueError('Number of combinations must be between 1 and 20') return v class CombinationResult(BaseModel): combination_id: int modules: List[ModuleData] schedule_grid: dict # Day -> time slots mapping class SearchResponse(BaseModel): success: bool combinations: List[CombinationResult] = [] message: str = "" error: Optional[str] = None