"""
Pydantic schemas for request/response validation.
Defines data models for API endpoints.
"""

from datetime import datetime
from enum import Enum
from typing import List, Optional

from pydantic import BaseModel, EmailStr, Field


# Enums
class UserType(str, Enum):
    """User type enumeration."""
    USER = "user"
    ADMIN = "admin"
    PARTNER = "partner"


class RateType(str, Enum):
    """Subscription rate enumeration."""
    FREE = "free"
    PREMIUM = "premium"
    PRO = "pro"


# Authentication schemas
class UserRegister(BaseModel):
    """User registration request schema."""
    name: str = Field(..., min_length=2, max_length=100, description="Full name")
    email: EmailStr = Field(..., description="Email address")
    password: str = Field(..., min_length=6, max_length=255, description="Password (min 6 chars)")


class UserLogin(BaseModel):
    """User login request schema."""
    email: EmailStr = Field(..., description="Email address")
    password: str = Field(..., description="Password")


class PasswordChange(BaseModel):
    """Password change request schema."""
    current_password: str = Field(..., description="Current password")
    new_password: str = Field(..., min_length=6, max_length=255, description="New password")


# Response schemas
class UserResponse(BaseModel):
    """User response schema."""
    id: int
    name: str
    email: str
    created_at: datetime
    rate: str
    paid: Optional[datetime] = None
    next_payment_date: Optional[datetime] = None
    user_type: str
    
    class Config:
        from_attributes = True


class TokenResponse(BaseModel):
    """Authentication token response schema."""
    access_token: str
    token_type: str = "bearer"
    expires_in: int
    user: UserResponse


class MessageResponse(BaseModel):
    """Generic message response schema."""
    message: str
    success: bool = True


class UserListResponse(BaseModel):
    """User list response schema."""
    users: List[UserResponse]
    total: int


# Profile update schemas
class UserUpdate(BaseModel):
    """User profile update request schema."""
    name: Optional[str] = Field(None, min_length=2, max_length=100)
    email: Optional[EmailStr] = None


# Admin schemas
class AdminUserCreate(BaseModel):
    """Admin user creation request schema."""
    name: str = Field(..., min_length=2, max_length=100)
    email: EmailStr = Field(..., description="Email address")
    password: str = Field(..., min_length=6, max_length=255)
    rate: RateType = RateType.FREE
    user_type: UserType = UserType.PARTNER
    paid: Optional[datetime] = None
    next_payment_date: Optional[datetime] = None


class AdminUserUpdate(BaseModel):
    """Admin user update request schema."""
    name: Optional[str] = Field(None, min_length=2, max_length=100)
    email: Optional[EmailStr] = None
    rate: Optional[RateType] = None
    user_type: Optional[UserType] = None
    paid: Optional[datetime] = None
    next_payment_date: Optional[datetime] = None


# Google OAuth schemas
class GoogleAuthRequest(BaseModel):
    """Google OAuth authentication request schema."""
    id_token: str = Field(..., description="Google ID token")


class GoogleAuthCodeRequest(BaseModel):
    """Google OAuth authorization code request schema."""
    code: str = Field(..., description="Authorization code from Google")


class GoogleOAuthUrlResponse(BaseModel):
    """Google OAuth URL response schema."""
    auth_url: str = Field(..., description="Google OAuth authorization URL") 