from sqlalchemy import Column, Integer, String, DECIMAL, ForeignKey, TIMESTAMP, JSON
from sqlalchemy.orm import relationship
from datetime import datetime
from app.database.database import Base


class Model(Base):
    __tablename__ = "model"

    id = Column(Integer, primary_key=True, index=True)
    name = Column(String(255), nullable=False)
    category_id = Column(Integer, ForeignKey("category.id", ondelete="CASCADE"), nullable=False)
    brand = Column(String(100), nullable=False)
    base_price = Column(DECIMAL(10, 2), nullable=True)
    sizes = Column(JSON, nullable=True)
    stock = Column(Integer, nullable=True)
    description = Column(String, nullable=True)
    created_at = Column(TIMESTAMP, default=datetime.utcnow)

    # Relationships
    category = relationship("Category", backref="models")
    products = relationship("Product", back_populates="model")
