from datetime import datetime
from typing import Optional
from uuid import UUID
from pydantic import BaseModel, Field


class MaintenanceScheduleCreate(BaseModel):
    tree_id: UUID
    cron_expression: str = Field(..., min_length=9, max_length=100)
    timezone: str = Field("UTC", max_length=100)
    target_list_id: Optional[UUID] = None


class MaintenanceScheduleUpdate(BaseModel):
    cron_expression: Optional[str] = Field(None, min_length=9, max_length=100)
    timezone: Optional[str] = Field(None, max_length=100)
    target_list_id: Optional[UUID] = None
    is_active: Optional[bool] = None


class MaintenanceScheduleResponse(BaseModel):
    id: UUID
    tree_id: UUID
    created_by: Optional[UUID]
    cron_expression: str
    timezone: str
    target_list_id: Optional[UUID]
    is_active: bool
    next_run_at: Optional[datetime]
    last_run_at: Optional[datetime]
    created_at: datetime
    updated_at: datetime

    model_config = {"from_attributes": True}
