from app.extensions import db
from datetime import datetime

class Contract(db.Model):
    __tablename__ = 'contracts'

    id = db.Column(db.Integer, primary_key=True)
    company_id = db.Column(db.Integer, db.ForeignKey('companies.id'), nullable=False)
    name = db.Column(db.String(300), nullable=False)
    belegnummer = db.Column(db.String(100))
    beleg_datum = db.Column(db.Date)
    laufzeit_start = db.Column(db.Date)
    laufzeit_ende = db.Column(db.Date)
    status = db.Column(db.String(50), default='NEU')  # NEU, Zur Prüfung, Angenommen
    erstellt_am = db.Column(db.DateTime, default=datetime.utcnow)

    projekte = db.relationship('Project', backref='contract', lazy='dynamic')

    def __repr__(self):
        return f'<Contract {self.name}>'
