"""
Classroom API - Context, Event, Routine Pydantic Models.
"""

from typing import Optional
from pydantic import BaseModel, Field


# === Context Models ===

class SchoolInfo(BaseModel):
    """Schul-Informationen."""
    federal_state: str
    federal_state_name: str = ""
    school_type: str
    school_type_name: str = ""


class SchoolYearInfo(BaseModel):
    """Schuljahr-Informationen."""
    id: str
    start: Optional[str] = None
    current_week: int = 1


class MacroPhaseInfo(BaseModel):
    """Makro-Phase Informationen."""
    id: str
    label: str
    confidence: float = 1.0


class CoreCounts(BaseModel):
    """Kern-Zaehler fuer den Kontext."""
    classes: int = 0
    exams_scheduled: int = 0
    corrections_pending: int = 0


class ContextFlags(BaseModel):
    """Status-Flags des Kontexts."""
    onboarding_completed: bool = False
    has_classes: bool = False
    has_schedule: bool = False
    is_exam_period: bool = False
    is_before_holidays: bool = False


class TeacherContextResponse(BaseModel):
    """Response fuer GET /v1/context."""
    schema_version: str = "1.0"
    teacher_id: str
    school: SchoolInfo
    school_year: SchoolYearInfo
    macro_phase: MacroPhaseInfo
    core_counts: CoreCounts
    flags: ContextFlags


class UpdateContextRequest(BaseModel):
    """Request zum Aktualisieren des Kontexts."""
    federal_state: Optional[str] = None
    school_type: Optional[str] = None
    schoolyear: Optional[str] = None
    schoolyear_start: Optional[str] = None
    macro_phase: Optional[str] = None
    current_week: Optional[int] = None


# === Event Models ===

class CreateEventRequest(BaseModel):
    """Request zum Erstellen eines Events."""
    title: str
    event_type: str = "other"
    start_date: str
    end_date: Optional[str] = None
    class_id: Optional[str] = None
    subject: Optional[str] = None
    description: str = ""
    needs_preparation: bool = True
    reminder_days_before: int = 7


class EventResponse(BaseModel):
    """Response fuer ein Event."""
    id: str
    teacher_id: str
    event_type: str
    title: str
    description: str
    start_date: str
    end_date: Optional[str]
    class_id: Optional[str]
    subject: Optional[str]
    status: str
    needs_preparation: bool
    preparation_done: bool
    reminder_days_before: int


# === Routine Models ===

class CreateRoutineRequest(BaseModel):
    """Request zum Erstellen einer Routine."""
    title: str
    routine_type: str = "other"
    recurrence_pattern: str = "weekly"
    day_of_week: Optional[int] = None
    day_of_month: Optional[int] = None
    time_of_day: Optional[str] = None
    duration_minutes: int = 60
    description: str = ""


class RoutineResponse(BaseModel):
    """Response fuer eine Routine."""
    id: str
    teacher_id: str
    routine_type: str
    title: str
    description: str
    recurrence_pattern: str
    day_of_week: Optional[int]
    day_of_month: Optional[int]
    time_of_day: Optional[str]
    duration_minutes: int
    is_active: bool
