"""
Distribution Models
"""
from sqlalchemy import Column, Integer, String, Text, Boolean, DateTime, ForeignKey, UniqueConstraint
from sqlalchemy.sql import func
from app.core.database import Base


class DistributionList(Base):
    """Distribution lists table"""
    __tablename__ = "distribution_lists"
    
    id = Column(Integer, primary_key=True, autoincrement=True)
    name = Column(Text, nullable=False)
    description = Column(Text)
    created_by = Column(Text, nullable=False)
    is_active = Column(Boolean, default=True)
    created_at = Column(DateTime, default=func.now())
    updated_at = Column(DateTime, default=func.now(), onupdate=func.now())


class DistributionListEmail(Base):
    """Distribution list emails table"""
    __tablename__ = "distribution_list_emails"
    
    id = Column(Integer, primary_key=True, autoincrement=True)
    distribution_list_id = Column(Integer, ForeignKey("distribution_lists.id", ondelete="CASCADE"), nullable=False)
    email = Column(Text, nullable=False)
    name = Column(Text)
    is_active = Column(Boolean, default=True)
    created_at = Column(DateTime, default=func.now())
    
    __table_args__ = (
        UniqueConstraint('distribution_list_id', 'email', name='uq_dist_list_email'),
    )
