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

from database import Base


class Gruppe(Base):
    __tablename__ = "gruppe"

    id = Column(Integer, primary_key=True, autoincrement=True)
    kuerzel = Column(String(10), unique=True, nullable=False)
    name = Column(String(100), nullable=False)
    beschreibung = Column(Text)
    farbe = Column(String(7), default="#607D8B")

    kontakte = relationship("KontaktGruppe", back_populates="gruppe", cascade="all, delete-orphan")


class KontaktGruppe(Base):
    __tablename__ = "kontakt_gruppe"

    kontakt_id = Column(Integer, ForeignKey("kontakt.id", ondelete="CASCADE"), primary_key=True)
    gruppe_id = Column(Integer, ForeignKey("gruppe.id", ondelete="CASCADE"), primary_key=True)

    kontakt = relationship("Kontakt", back_populates="gruppen")
    gruppe = relationship("Gruppe", back_populates="kontakte")
