from datetime import datetime
from app.extensions import db

class AufmassHistory(db.Model):
    __tablename__ = 'aufmass_history'

    id = db.Column(db.Integer, primary_key=True)
    aufmass_id = db.Column(db.Integer, db.ForeignKey('aufmass.id'), nullable=False, index=True)
    position_id = db.Column(db.Integer, db.ForeignKey('positionen.id', ondelete='SET NULL'), nullable=True)
    changed_by = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
    changed_at = db.Column(db.DateTime, default=datetime.utcnow, index=True)
    action = db.Column(db.String(10), nullable=False)
    description = db.Column(db.String(500), nullable=True)
    diff = db.Column(db.Text, nullable=False)

    def __repr__(self):
        return f'<AufmassHistory {self.id} {self.action} @ {self.changed_at}>'
