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


class LoginRequest(BaseModel):
    email: EmailStr
    password: str


class LoginResponse(BaseModel):
    access_token: str
    token_type: str = "bearer"
    user_id: str
    role: str


class MicrosoftLoginRequest(BaseModel):
    """Request schema for Microsoft authentication."""
    id_token: str


class MicrosoftLoginResponse(BaseModel):
    """Response schema for Microsoft authentication."""
    access_token: str
    token_type: str = "bearer"
    user_id: str
    role: str
    email: str
    full_name: str
    auth_provider: AuthProvider


class RefreshResponse(BaseModel):
    access_token: str
    token_type: str = "bearer"
    user_id: str
    role: str
    email: str
    full_name: str


class LogoutResponse(BaseModel):
    message: str = "Successfully logged out"


# User management schemas for admin routes
class UserResponse(BaseModel):
    id: str
    email: EmailStr
    full_name: str
    role: UserRole
    auth_provider: AuthProvider
    is_active: bool
    created_at: Optional[str] = None


class UserListResponse(BaseModel):
    users: list[UserResponse]
    total: int
    page: int
    size: int


class CreateUserRequest(BaseModel):
    email: EmailStr
    password: str
    full_name: str
    role: UserRole = UserRole.CLIENT


class UpdateUserRequest(BaseModel):
    email: Optional[EmailStr] = None
    full_name: Optional[str] = None
    role: Optional[UserRole] = None
    is_active: Optional[bool] = None


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


class ResetPasswordRequest(BaseModel):
    email: EmailStr


class AdminStatsResponse(BaseModel):
    total_users: int
    total_jobs: int
    jobs_by_status: dict[str, int]
    active_jobs_today: int
    avg_processing_time_hours: float
