from pydantic import BaseModel
from typing import Optional, List
from datetime import datetime
from decimal import Decimal


class ProductCreate(BaseModel):
    name: str
    slug: Optional[str] = None
    description: str
    price: Optional[float] = None  # Optional - inherits from model if not set
    discount_price: Optional[float] = None
    category_id: int
    model_id: Optional[int] = None
    gender: str = 'Unisex'  # men, women, unisex
    brand: str
    sizes: Optional[List[str]] = []
    colors: Optional[List[str]] = []
    stock: Optional[int] = None
    images: Optional[List[str]] = []
    main_image_url: Optional[str] = None  # Main image for listings
    rating_average: Optional[float] = 0.0
    rating_count: Optional[int] = 0
    is_featured: bool = False
    is_on_sale: bool = False
    override_price: Optional[Decimal] = None
    override_sizes: Optional[List[str]] = None


class ProductUpdate(BaseModel):
    name: Optional[str] = None
    slug: Optional[str] = None
    description: Optional[str] = None
    price: Optional[float] = None
    discount_price: Optional[float] = None
    category_id: Optional[int] = None
    model_id: Optional[int] = None
    gender: Optional[str] = None
    brand: Optional[str] = None
    sizes: Optional[List[str]] = None
    colors: Optional[List[str]] = None
    stock: Optional[int] = None
    images: Optional[List[str]] = None
    main_image_url: Optional[str] = None
    rating_average: Optional[float] = None
    rating_count: Optional[int] = None
    is_featured: Optional[bool] = None
    is_on_sale: Optional[bool] = None
    override_price: Optional[Decimal] = None
    override_sizes: Optional[List[str]] = None


class ProductResponse(BaseModel):
    id: int
    name: str
    slug: Optional[str]
    description: str
    price: Optional[float]  # May be None if inherited from model
    discount_price: Optional[float]
    category_id: int
    model_id: Optional[int]
    gender: str
    brand: str
    sizes: Optional[List[str]]
    colors: Optional[List[str]]
    stock: Optional[int]
    images: Optional[List[str]]
    main_image_url: Optional[str]
    rating_average: Optional[float]
    rating_count: Optional[int]
    is_featured: bool
    is_on_sale: bool
    override_price: Optional[Decimal]
    override_sizes: Optional[List[str]]
    category_name: Optional[str] = None
    created_at: datetime

    class Config:
        from_attributes = True


class ProductDetailResponse(ProductResponse):
    pass
