# models/schema/vendor_product.py
"""
Pydantic schemas for vendor product catalog operations.

Used by admin vendor product endpoints for:
- Product listing and filtering
- Product statistics
- Product detail views
- Catalog vendor listings
"""

from pydantic import BaseModel, ConfigDict


class VendorProductListItem(BaseModel):
    """Product item for vendor catalog list view."""

    model_config = ConfigDict(from_attributes=True)

    id: int
    vendor_id: int
    vendor_name: str | None = None
    vendor_code: str | None = None
    marketplace_product_id: int
    vendor_sku: str | None = None
    title: str | None = None
    brand: str | None = None
    effective_price: float | None = None
    effective_currency: str | None = None
    is_active: bool | None = None
    is_featured: bool | None = None
    is_digital: bool | None = None
    image_url: str | None = None
    source_marketplace: str | None = None
    source_vendor: str | None = None
    created_at: str | None = None
    updated_at: str | None = None


class VendorProductListResponse(BaseModel):
    """Paginated vendor product list response."""

    products: list[VendorProductListItem]
    total: int
    skip: int
    limit: int


class VendorProductStats(BaseModel):
    """Vendor product statistics."""

    total: int
    active: int
    inactive: int
    featured: int
    digital: int
    physical: int
    by_vendor: dict[str, int]


class CatalogVendor(BaseModel):
    """Vendor with products in catalog."""

    id: int
    name: str
    vendor_code: str


class CatalogVendorsResponse(BaseModel):
    """Response for catalog vendors list."""

    vendors: list[CatalogVendor]


class VendorProductDetail(BaseModel):
    """Detailed vendor product information."""

    id: int
    vendor_id: int
    vendor_name: str | None = None
    vendor_code: str | None = None
    marketplace_product_id: int
    vendor_sku: str | None = None
    # Override info from get_override_info()
    price: float | None = None
    price_overridden: bool | None = None
    price_source: float | None = None
    sale_price: float | None = None
    sale_price_overridden: bool | None = None
    sale_price_source: float | None = None
    currency: str | None = None
    currency_overridden: bool | None = None
    currency_source: str | None = None
    brand: str | None = None
    brand_overridden: bool | None = None
    brand_source: str | None = None
    condition: str | None = None
    condition_overridden: bool | None = None
    condition_source: str | None = None
    availability: str | None = None
    availability_overridden: bool | None = None
    availability_source: str | None = None
    primary_image_url: str | None = None
    primary_image_url_overridden: bool | None = None
    primary_image_url_source: str | None = None
    is_digital: bool | None = None
    product_type: str | None = None
    # Vendor-specific fields
    is_featured: bool | None = None
    is_active: bool | None = None
    display_order: int | None = None
    min_quantity: int | None = None
    max_quantity: int | None = None
    # Supplier tracking
    supplier: str | None = None
    supplier_product_id: str | None = None
    cost: float | None = None  # What vendor pays to acquire product
    margin_percent: float | None = None
    # Tax/profit info
    tax_rate_percent: int | None = None
    net_price: float | None = None
    vat_amount: float | None = None
    profit: float | None = None
    profit_margin_percent: float | None = None
    # Digital fulfillment
    download_url: str | None = None
    license_type: str | None = None
    fulfillment_email_template: str | None = None
    # Source info
    source_marketplace: str | None = None
    source_vendor: str | None = None
    source_gtin: str | None = None
    source_sku: str | None = None
    # Translations
    marketplace_translations: dict | None = None
    vendor_translations: dict | None = None
    # Timestamps
    created_at: str | None = None
    updated_at: str | None = None


class RemoveProductResponse(BaseModel):
    """Response from product removal."""

    message: str
