from datetime import datetime

from sqlalchemy import Column, DateTime, ForeignKey, Integer, String, Text
from sqlalchemy.orm import relationship

from database import Base


class Dokument(Base):
    __tablename__ = "dokument"

    id = Column(Integer, primary_key=True, autoincrement=True)
    kontakt_id = Column(Integer, ForeignKey("kontakt.id", ondelete="SET NULL"), nullable=True)
    aktivitaet_id = Column(Integer, ForeignKey("aktivitaet.id", ondelete="SET NULL"), nullable=True)
    veranstaltung_id = Column(Integer, ForeignKey("veranstaltung.id", ondelete="SET NULL"), nullable=True)

    dateiname = Column(String(300), nullable=False)
    dateipfad = Column(String(500), nullable=False)
    dateityp = Column(String(50))
    dateigroesse = Column(Integer)
    beschreibung = Column(Text)

    erfasst_am = Column(DateTime, default=datetime.now)
    erfasst_von = Column(String(10))

    kontakt = relationship("Kontakt", back_populates="dokumente")
    aktivitaet = relationship("Aktivitaet", back_populates="dokumente")
    veranstaltung = relationship("Veranstaltung", back_populates="dokumente")
