from app.extensions import db
from datetime import datetime

class Company(db.Model):
    __tablename__ = 'companies'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(200), nullable=False)
    slug = db.Column(db.String(100), unique=True, nullable=False)
    strasse = db.Column(db.String(200))
    house_number = db.Column(db.String(20))
    plz = db.Column(db.String(10))
    ort = db.Column(db.String(100))
    telefon = db.Column(db.String(50))
    email = db.Column(db.String(200))
    logo = db.Column(db.String(500))
    aktiv = db.Column(db.Boolean, default=True)
    evergabe_aktiviert = db.Column(db.Boolean, default=False)
    evergabe_benutzer = db.Column(db.String(200))
    evergabe_passwort = db.Column(db.String(300))
    evergabe_name = db.Column(db.String(200))
    erstellt_am = db.Column(db.DateTime, default=datetime.utcnow)

    users = db.relationship('User', backref='company', lazy='dynamic')
    licenses = db.relationship('License', backref='company', lazy='dynamic')
    projekte = db.relationship('Project', backref='company', lazy='dynamic')

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