from pydantic import BaseModel, EmailStr
from typing import Optional
from datetime import datetime
from models.user import UserRole


class UserBase(BaseModel):
    email: EmailStr
    first_name: str
    last_name: str


class UserCreate(UserBase):
    password: str


class UserUpdate(BaseModel):
    first_name: Optional[str] = None
    last_name: Optional[str] = None
    role: Optional[UserRole] = None
    is_admin: Optional[bool] = None
    is_approved: Optional[bool] = None


class UserResponse(UserBase):
    id: int
    role: UserRole
    is_admin: bool
    is_approved: bool
    avatar_url: Optional[str] = None
    created_at: datetime
    updated_at: datetime

    class Config:
        from_attributes = True


class UserApproval(BaseModel):
    is_approved: bool


class UserRoleUpdate(BaseModel):
    role: UserRole


class UserAdminUpdate(BaseModel):
    is_admin: bool


class UserAdminCreate(BaseModel):
    email: EmailStr
    password: str
    first_name: str
    last_name: str
    role: UserRole
    is_approved: bool = True
    is_admin: bool = False


class UserAdminEdit(BaseModel):
    first_name: Optional[str] = None
    last_name: Optional[str] = None
    email: Optional[EmailStr] = None
    role: Optional[UserRole] = None
    is_approved: Optional[bool] = None
    is_admin: Optional[bool] = None


class UserPasswordReset(BaseModel):
    new_password: str


class UserPasswordChange(BaseModel):
    current_password: str
    new_password: str