from pydantic import BaseModel, Field, validator
from typing import Optional
from datetime import datetime


class ReviewBase(BaseModel):
    product_id: int
    rating: int = Field(..., ge=1, le=5)
    title: Optional[str] = None
    comment: Optional[str] = None


class ReviewCreate(ReviewBase):
    pass


class ReviewUpdate(BaseModel):
    rating: Optional[int] = Field(None, ge=1, le=5)
    title: Optional[str] = None
    comment: Optional[str] = None
    is_approved: Optional[bool] = None


class Review(ReviewBase):
    id: int
    user_id: int
    is_verified_purchase: bool
    is_approved: bool
    created_at: datetime
    updated_at: Optional[datetime] = None

    class Config:
        orm_mode = True


class ReviewWithUser(Review):
    user_email: str 