from database.database import db

class ProjectClass(db.Model):
    """Class definitions for training projects (3NF)"""
    __tablename__ = 'project_class'
    
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    project_id = db.Column(db.Integer, db.ForeignKey('training_project.project_id', ondelete='CASCADE'), nullable=False)
    class_name = db.Column(db.String(255), nullable=False)
    display_order = db.Column(db.Integer, default=0)
    
    # Unique constraint: one class name per project
    __table_args__ = (
        db.UniqueConstraint('project_id', 'class_name', name='uq_project_class'),
    )
    
    def to_dict(self):
        return {
            'id': self.id,
            'project_id': self.project_id,
            'class_name': self.class_name,
            'display_order': self.display_order
        }
