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

# Bestehendes Einzeilen-Schema bleibt
class DeliveryBase(BaseModel):
    product_id: int
    amount: int
    price_cents: int
    delivered_at: Optional[date] = None
    supplier: Optional[str] = None
    invoice_number: Optional[str] = None
    created_by: Optional[int] = None
    note: str | None = None 
    deposit_return_cents: int = 0
    model_config = ConfigDict(from_attributes=True)  # statt orm_mode

class DeliveryCreate(DeliveryBase):
    pass

class DeliveryOut(DeliveryBase):
    id: int
    class Config:
        from_attributes = True

# 🆕 Für die neue Seite (Header + Items + Pfand)
class DeliveryItemIn(BaseModel):
    product_id: int
    quantity_units: int
    unit_cost_cents: int

class DeliveryCreateBulk(BaseModel):
    supplier: Optional[str] = None
    date: Optional[date] = None
    invoice_no: Optional[str] = None
    note: Optional[str] = None
    deposit_return_cents: int = 0  # Netto-Pfand (Cent, positiv)
    items: List[DeliveryItemIn]
