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

class UserIDRequest(BaseModel):
    id: int

class RegisterUserRequest(BaseModel):
    name: str
    email: str
    rut: str

class ForceRegisterUserRequest(BaseModel):
    name: str
    email: str
    rut: str
    pin: str = Field(min_length=4, max_length=4, description="4-digit PIN for user authentication")

class UserRewardRequest(BaseModel):
    tableNumber: int

class PinUserRequest(BaseModel):
    pin: str = Field(min_length=4, max_length=4, description="4-digit PIN for user authentication")

class User(BaseModel):
    """User model matching the database schema"""
    id: int
    email: str
    name: str
    rut: str
    pin_hash: str
    kleincoins: str
    created_at: str
    permissions: Optional[int] = 0  # Default to normal user
    reward_progress:int

class UserMail(BaseModel):
    email: str
class LoginRequest(BaseModel):
    email: str
    pin: str = Field(min_length=4, max_length=4, description="4-digit PIN for user authentication")

class PinRecoveryRequest(BaseModel):
    email: str
    token: Optional[str] = None
    new_pin: Optional[str] = Field(min_length=4, max_length=4, description="4-digit PIN for user authentication")

class PinRecoveryValidateRequest(BaseModel):
    email: str
    code: int