"""
Pydantic Schemas for API Request/Response validation
"""
from pydantic import BaseModel, Field, ConfigDict
from typing import List, Optional
from datetime import datetime
import uuid


# ==================== AUTH SCHEMAS ====================

class AdminLogin(BaseModel):
    username: str
    password: str


class Token(BaseModel):
    access_token: str
    token_type: str


# ==================== BLOG SCHEMAS ====================

class BlogPostCreate(BaseModel):
    title: str
    slug: str = ""
    content: str
    excerpt: str = ""
    meta_description: str = ""
    meta_keywords: str = ""
    author: str = "Admin"
    featured_image: str = ""
    status: str = "published"


class BlogPostUpdate(BaseModel):
    title: Optional[str] = None
    slug: Optional[str] = None
    content: Optional[str] = None
    excerpt: Optional[str] = None
    meta_description: Optional[str] = None
    meta_keywords: Optional[str] = None
    author: Optional[str] = None
    featured_image: Optional[str] = None
    status: Optional[str] = None


class BlogPostResponse(BaseModel):
    model_config = ConfigDict(from_attributes=True)
    
    id: str
    title: str
    slug: str
    content: str
    excerpt: str
    meta_description: str
    meta_keywords: str
    author: str
    featured_image: str
    status: str
    views: int
    created_at: datetime
    updated_at: datetime


# ==================== SERVICE SCHEMAS ====================

class ServiceCreate(BaseModel):
    title: str
    description: str
    icon: str = "wrench"
    order: int = 0


class ServiceResponse(BaseModel):
    model_config = ConfigDict(from_attributes=True, populate_by_name=True)
    
    id: str
    title: str
    description: str
    icon: str
    order: int = Field(default=0, validation_alias="order_num", serialization_alias="order")


# ==================== BRAND SCHEMAS ====================

class BrandCreate(BaseModel):
    name: str
    logo_url: str
    alt_text: str = ""
    order: int = 0


class BrandResponse(BaseModel):
    model_config = ConfigDict(from_attributes=True, populate_by_name=True)
    
    id: str
    name: str
    logo_url: str
    alt_text: str
    order: int = Field(default=0, validation_alias="order_num", serialization_alias="order")


# ==================== AREA SCHEMAS ====================

class AreaCreate(BaseModel):
    province: str
    cities: List[str]


class AreaResponse(BaseModel):
    model_config = ConfigDict(from_attributes=True)
    
    id: str
    province: str
    cities: List[str]


# ==================== CONTACT SCHEMAS ====================

class ContactUpdate(BaseModel):
    phone: Optional[str] = None
    email: Optional[str] = None
    address: Optional[str] = None
    hours: Optional[str] = None
    map_embed: Optional[str] = None


class ContactResponse(BaseModel):
    model_config = ConfigDict(from_attributes=True)
    
    id: str
    phone: str
    email: str
    address: str
    hours: str
    map_embed: str


# ==================== ABOUT SCHEMAS ====================

class AboutCardCreate(BaseModel):
    title: str
    description: str
    order: int = 0


class AboutCardResponse(BaseModel):
    model_config = ConfigDict(from_attributes=True, populate_by_name=True)
    
    id: str
    title: str
    description: str
    order: int = Field(default=0, validation_alias="order_num", serialization_alias="order")


# ==================== PRODUCT SCHEMAS ====================

class ProductCreate(BaseModel):
    name: str
    slug: str = ""
    description: str
    price: float
    original_price: float = 0
    category: str = "Spareparts"
    brand: str = ""
    images: List[str] = []
    stock: int = 0
    is_available: bool = True
    featured: bool = False


class ProductUpdate(BaseModel):
    name: Optional[str] = None
    slug: Optional[str] = None
    description: Optional[str] = None
    price: Optional[float] = None
    original_price: Optional[float] = None
    category: Optional[str] = None
    brand: Optional[str] = None
    images: Optional[List[str]] = None
    stock: Optional[int] = None
    is_available: Optional[bool] = None
    featured: Optional[bool] = None


class ProductResponse(BaseModel):
    model_config = ConfigDict(from_attributes=True)
    
    id: str
    name: str
    slug: str
    description: str
    price: float
    original_price: float
    category: str
    brand: str
    images: List[str]
    stock: int
    is_available: bool
    featured: bool
    created_at: datetime
    updated_at: datetime
