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


class UserBase(BaseModel):
    email: EmailStr
    full_name: str


class UserCreate(UserBase):
    password: str
    username: Optional[str] = None
    phone: Optional[str] = None


class UserUpdate(BaseModel):
    full_name: Optional[str] = None
    username: Optional[str] = None
    phone: Optional[str] = None
    address: Optional[str] = None
    city: Optional[str] = None
    postal_code: Optional[str] = None
    country: Optional[str] = None
    email: Optional[EmailStr] = None


class ChangePasswordRequest(BaseModel):
    old_password: str
    new_password: str


class RequestPinRequest(BaseModel):
    email: EmailStr


class ResetPasswordWithPinRequest(BaseModel):
    email: EmailStr
    pin: str
    new_password: str


class UserResponse(UserBase):
    id: int
    username: Optional[str]
    phone: Optional[str]
    address: Optional[str]
    city: Optional[str]
    postal_code: Optional[str]
    country: Optional[str]
    is_active: bool
    is_admin: bool
    must_change_password: bool = False
    created_at: datetime

    class Config:
        from_attributes = True
