from pydantic import BaseModel
from typing import Optional, Dict, Any
from datetime import datetime


# Схемы для информационных страниц
class PageBase(BaseModel):
    title: str
    slug: str
    content: str
    meta_title: Optional[str] = None
    meta_description: Optional[str] = None
    is_published: bool = True


class PageCreate(PageBase):
    pass


class PageUpdate(BaseModel):
    title: Optional[str] = None
    slug: Optional[str] = None
    content: Optional[str] = None
    meta_title: Optional[str] = None
    meta_description: Optional[str] = None
    is_published: Optional[bool] = None


class Page(PageBase):
    id: int
    created_at: datetime
    updated_at: Optional[datetime] = None

    class Config:
        orm_mode = True


# Схемы для аналитики
class AnalyticsLogBase(BaseModel):
    event_type: str
    page_url: Optional[str] = None
    product_id: Optional[int] = None
    category_id: Optional[int] = None
    ip_address: Optional[str] = None
    user_agent: Optional[str] = None
    referrer: Optional[str] = None
    additional_data: Optional[Dict[str, Any]] = None


class AnalyticsLogCreate(AnalyticsLogBase):
    user_id: Optional[int] = None


class AnalyticsLog(AnalyticsLogBase):
    id: int
    user_id: Optional[int] = None
    created_at: datetime

    class Config:
        orm_mode = True


# Схемы для аналитических отчетов
class AnalyticsReport(BaseModel):
    period: str  # day, week, month, year
    start_date: datetime
    end_date: datetime
    total_visits: int
    unique_visitors: int
    page_views: Dict[str, int]
    product_views: Dict[str, int]
    cart_additions: int
    orders_count: int
    revenue: float
    average_order_value: float 