from database.database import db

class TrainingSize(db.Model):
    """Size configurations for training (3NF - replaces JSON arrays)"""
    __tablename__ = 'training_size'
    
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    training_id = db.Column(db.Integer, db.ForeignKey('training.id', ondelete='CASCADE'), nullable=False)
    size_type = db.Column(db.String(50), nullable=False)  # 'input_size', 'test_size', 'mosaic_scale', 'mixup_scale'
    value_order = db.Column(db.Integer, nullable=False, default=0)  # Order in array (0=first, 1=second)
    value = db.Column(db.Float, nullable=False)
    
    # Composite key ensures proper ordering
    __table_args__ = (
        db.UniqueConstraint('training_id', 'size_type', 'value_order', name='uq_training_size'),
    )
    
    def to_dict(self):
        return {
            'id': self.id,
            'training_id': self.training_id,
            'size_type': self.size_type,
            'value_order': self.value_order,
            'value': self.value
        }
