from sqlalchemy import Column, Integer, String, DateTime, Enum as SAEnum, Boolean from sqlalchemy.orm import relationship from sqlalchemy.sql import func from database import Base class User(Base): __tablename__ = "users" id = Column(Integer, primary_key=True, index=True) phone = Column(String(20), unique=True, index=True, nullable=False) password_hash = Column(String(255), nullable=False) name = Column(String(50), nullable=False) avatar = Column(String(500), default="") subject = Column(String(50), default="") school = Column(String(100), default="") grade = Column(String(50), default="") role = Column(SAEnum("teacher", "admin", name="user_role"), default="teacher") is_active = Column(Boolean, default=True) created_at = Column(DateTime, server_default=func.now()) updated_at = Column(DateTime, server_default=func.now(), onupdate=func.now()) coursewares = relationship("Courseware", back_populates="author", lazy="selectin") animations = relationship("Animation", back_populates="author", lazy="selectin") exercises = relationship("Exercise", back_populates="author", lazy="selectin") lesson_plans = relationship("LessonPlan", back_populates="author", lazy="selectin") essay_grades = relationship("EssayGrade", back_populates="author", lazy="selectin", cascade="all, delete-orphan") resources = relationship("Resource", back_populates="author", lazy="selectin") materials = relationship("Material", back_populates="author", lazy="selectin", cascade="all, delete-orphan") resource_favorites = relationship("ResourceFavorite", back_populates="user", lazy="selectin", cascade="all, delete-orphan") posts = relationship("Post", back_populates="author", lazy="selectin") credit_account = relationship("CreditAccount", back_populates="user", uselist=False, lazy="selectin", cascade="all, delete-orphan") credit_transactions = relationship("CreditTransaction", back_populates="user", lazy="selectin", cascade="all, delete-orphan") mind_maps = relationship("MindMap", back_populates="author", lazy="selectin", cascade="all, delete-orphan") notifications = relationship("Notification", back_populates="user", lazy="selectin", cascade="all, delete-orphan") chat_conversations = relationship("ChatConversation", back_populates="author", lazy="selectin", cascade="all, delete-orphan")