from pydantic import BaseModel, Field, field_validator
from typing import Optional, List
from datetime import datetime

class FolderCreate(BaseModel):
    name: str = Field(..., min_length=1, max_length=255)
    parent_id: Optional[str] = None

    @field_validator('name')
    @classmethod
    def validate_name(cls, v):
        forbidden = '/\\*?:'
        for c in forbidden:
            if c in v:
                raise ValueError(f'Folder name cannot contain: {forbidden}')
        return v

class FolderUpdate(BaseModel):
    name: str = Field(..., min_length=1, max_length=255)

class FolderOut(BaseModel):
    id: str
    name: str
    parent_id: Optional[str]
    created_at: datetime
    updated_at: datetime

    model_config = {"from_attributes": True}

class FolderTreeOut(BaseModel):
    id: str
    name: str
    parent_id: Optional[str]
    children: List["FolderTreeOut"] = []

    model_config = {"from_attributes": True}

# 递归模型需要 forward ref
FolderTreeOut.model_rebuild()
