from __future__ import annotations
from datetime import datetime
from sqlalchemy.orm import Mapped, mapped_column
from sqlalchemy import String, Integer, Float, Boolean, DateTime, ForeignKey
from .db import Base
class Product(Base):
__tablename__ = "products"
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
name: Mapped[str] = mapped_column(String(255), nullable=False)
price: Mapped[float] = mapped_column(Float, nullable=False)
category: Mapped[str] = mapped_column(String(255), nullable=False)
in_stock: Mapped[bool] = mapped_column(Boolean, default=True, nullable=False)
class Order(Base):
__tablename__ = "orders"
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
product_id: Mapped[int] = mapped_column(ForeignKey("products.id"), nullable=False)
quantity: Mapped[int] = mapped_column(Integer, nullable=False)
total_price: Mapped[float] = mapped_column(Float, nullable=False)
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, nullable=False)