from datetime import datetime

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

from database import Base


class Spende(Base):
    __tablename__ = "spende"

    id = Column(Integer, primary_key=True, autoincrement=True)
    kontakt_id = Column(Integer, ForeignKey("kontakt.id", ondelete="CASCADE"), nullable=False)
    betrag = Column(Float, nullable=False)
    datum = Column(Date, nullable=False)
    typ = Column(String(50), default="einzelspende")  # einzelspende, dauerspende
    zweck = Column(String(300))
    projekt = Column(String(200))
    kampagne_id = Column(Integer, ForeignKey("kampagne.id", ondelete="SET NULL"), nullable=True)
    quittung = Column(String(50))  # keine, erstellt, versendet
    zahlungsart = Column(String(50))  # ueberweisung, bar, lastschrift
    bemerkung = Column(Text)

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

    kontakt = relationship("Kontakt", back_populates="spenden")
    kampagne = relationship("Kampagne", back_populates="spenden")
