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

class PurchaseItem(BaseModel):
    product_id: int
    unit_price: float
    quantity: int
    is_case: bool
    num_boxes: Optional[int] = None
    # TODO: remove is_case and num_boxes, should derive from product_id

class SaleItem(BaseModel):
    inventory_item_id: int
    unit_price: float

class PurchaseTransactionCreate(BaseModel):
    vendor_id: int
    transaction_date: datetime
    items: List[PurchaseItem]
    transaction_notes: Optional[str] = None

class SaleTransactionCreate(BaseModel):
    customer_id: int
    marketplace_id: Optional[int] = None
    transaction_date: datetime
    items: List[SaleItem]
    transaction_notes: Optional[str] = None

class TransactionItemResponse(BaseModel):
    id: int
    transaction_id: int
    physical_item_id: int
    unit_price: float
    created_at: datetime
    updated_at: datetime

class TransactionResponse(BaseModel):
    id: int
    vendor_id: Optional[int] = None
    customer_id: Optional[int] = None
    marketplace_id: Optional[int] = None
    transaction_type: str
    transaction_date: datetime
    transaction_total_amount: float
    transaction_notes: Optional[str] = None
    created_at: datetime
    updated_at: datetime
    transaction_items: List[TransactionItemResponse] 