"""Paper-only execution. This never calls a broker API."""
from app.db.database import SessionLocal
from app.db.models import PaperOrder


def place_paper_order(symbol: str, side: str, quantity: int, order_type: str = "MARKET", limit_price: float | None = None, note: str = "") -> int:
    if side not in {"BUY", "SELL"} or quantity <= 0:
        raise ValueError("side must be BUY/SELL and quantity must be positive")
    with SessionLocal() as session:
        order = PaperOrder(symbol=symbol, side=side, quantity=quantity, order_type=order_type, limit_price=limit_price, note=note)
        session.add(order)
        session.commit()
        return order.id
