
from pydantic import BaseModel, EmailStr

from ..models.user import AuthProvider, UserRole


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: str | None = None
    pm_client_ids: list[str] = []
    languages: list[str] = []  # BCP-47 codes for R-8 linguist competence check


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: EmailStr | None = None
    full_name: str | None = None
    role: UserRole | None = None
    is_active: bool | None = 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
