import uuid
from pydantic import BaseModel, Field, field_validator
import re

class UserCreate(BaseModel):
    username: str
    phone_number: str | None = Field(None, description="11 digit phone number")
    is_admin: bool = False

    @field_validator("phone_number")
    @classmethod
    def validate_phone_number(cls, v: str | None) -> str | None:
        if v is None:
            return v
        if not re.match(r"^09\d{9}$", v):
            raise ValueError("Phone number must start with 09 and be exactly 11 digits")
        return v

class UserResponse(BaseModel):
    id: uuid.UUID
    username: str
    phone_number: str | None
    is_admin: bool
    is_active: bool

    class Config:
        from_attributes = True

class UserCreateResult(BaseModel):
    user: UserResponse
    secret: str
