from sqlalchemy import ForeignKey, Column, Integer, JSON, TIMESTAMP, String, Enum from sqlalchemy.orm import relationship from .base_model import Base class User(Base): __tablename__ = "user" id = Column(Integer, primary_key=True) shop_id = Column(Integer, ForeignKey("shop.id"), nullable=True) username = Column(String(64), unique=True, nullable=False) email = Column(String(128), unique=True, nullable=False) password = Column(String(60), nullable=False) role = Column(Enum("customer", "employee", "manager", "owner", "admin", name="user_role"), nullable=False, default="customer") first_name = Column(String(64), nullable=True) last_name = Column(String(64), nullable=True) phone_number = Column(String(15), nullable=True) created_at = Column(TIMESTAMP, default="CURRENT_TIMESTAMP", nullable=True) updated_at = Column(TIMESTAMP, default="CURRENT_TIMESTAMP", nullable=True) last_login = Column(TIMESTAMP, default="CURRENT_TIMESTAMP", nullable=True) profile_picture = Column(String(100), nullable=True) preferences = Column(JSON, nullable=True) shop = relationship("Shop", back_populates="users") carts = relationship("Cart", back_populates="user") purchases = relationship("Purchase", back_populates="user") statistics = relationship("UserStatistics", back_populates="user") wishlists = relationship("Wishlist", back_populates="user") __all__ = ["User"]