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


class OrganizationBase(BaseModel):
    name: str = Field(..., min_length=1, max_length=100)
    description: Optional[str] = None
    sort_order: int = 0


class OrganizationCreate(OrganizationBase):
    pass


class OrganizationUpdate(BaseModel):
    """更新组织须填写图形验证码（管理员验证码）。"""

    name: Optional[str] = Field(None, min_length=1, max_length=100)
    description: Optional[str] = None
    sort_order: Optional[int] = None
    captcha_id: str = Field(..., min_length=1, description="图形验证码 ID")
    captcha_code: str = Field(..., min_length=1, description="图形验证码")


class OrganizationResponse(OrganizationBase):
    id: int
    created_at: datetime
    updated_at: datetime

    class Config:
        from_attributes = True
