from datetime import datetime from sqlalchemy import Boolean, DateTime, Enum, ForeignKey, Integer, String, Text, func from sqlalchemy.orm import Mapped, mapped_column, relationship from app.db.base import Base from app.models.enums import AdminRole, EventType, PlatformKind class AdminUser(Base): __tablename__ = "admin_users" id: Mapped[int] = mapped_column(Integer, primary_key=True) email: Mapped[str] = mapped_column(String(255), unique=True, index=True) hashed_password: Mapped[str] = mapped_column(String(255)) role: Mapped[AdminRole] = mapped_column(Enum(AdminRole), default=AdminRole.super_admin) created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now()) class NewsletterSubscriber(Base): __tablename__ = "newsletter_subscribers" id: Mapped[int] = mapped_column(Integer, primary_key=True) email: Mapped[str] = mapped_column(String(255), unique=True, index=True) neighborhood: Mapped[str | None] = mapped_column(String(120), nullable=True) created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now()) class AlertDispatch(Base): __tablename__ = "alert_dispatches" id: Mapped[int] = mapped_column(Integer, primary_key=True) alert_key: Mapped[str] = mapped_column(String(120), unique=True, index=True) created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now()) class PlatformLink(Base): __tablename__ = "platform_links" id: Mapped[int] = mapped_column(Integer, primary_key=True) kind: Mapped[PlatformKind] = mapped_column(Enum(PlatformKind), index=True) label: Mapped[str] = mapped_column(String(120)) url: Mapped[str] = mapped_column(String(512)) sort_order: Mapped[int] = mapped_column(Integer, default=0) is_active: Mapped[bool] = mapped_column(Boolean, default=True) created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now()) class EventEdition(Base): __tablename__ = "event_editions" id: Mapped[int] = mapped_column(Integer, primary_key=True) title: Mapped[str] = mapped_column(String(200)) slug: Mapped[str] = mapped_column(String(200), unique=True, index=True) event_type: Mapped[EventType] = mapped_column(Enum(EventType), index=True) city: Mapped[str] = mapped_column(String(80), default="Bengaluru") venue_name: Mapped[str | None] = mapped_column(String(200), nullable=True) event_date: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True) description: Mapped[str | None] = mapped_column(Text, nullable=True) is_published: Mapped[bool] = mapped_column(Boolean, default=False) is_featured: Mapped[bool] = mapped_column(Boolean, default=False) cover_image_path: Mapped[str | None] = mapped_column(String(512), nullable=True) bookmyshow_url: Mapped[str | None] = mapped_column(String(512), nullable=True) district_url: Mapped[str | None] = mapped_column(String(512), nullable=True) instagram_url: Mapped[str | None] = mapped_column(String(512), nullable=True) meta_description: Mapped[str | None] = mapped_column(String(320), nullable=True) sort_order: Mapped[int] = mapped_column(Integer, default=0) created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now()) media: Mapped[list["MediaAsset"]] = relationship( "MediaAsset", back_populates="edition", cascade="all, delete-orphan", order_by="MediaAsset.sort_order", ) class OutboundClick(Base): __tablename__ = "outbound_clicks" id: Mapped[int] = mapped_column(Integer, primary_key=True) link_kind: Mapped[str] = mapped_column(String(64), index=True) destination_url: Mapped[str] = mapped_column(String(512)) edition_id: Mapped[int | None] = mapped_column( ForeignKey("event_editions.id", ondelete="SET NULL"), nullable=True, index=True, ) referrer: Mapped[str | None] = mapped_column(String(512), nullable=True) user_agent: Mapped[str | None] = mapped_column(String(512), nullable=True) created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now(), index=True) class MediaAsset(Base): __tablename__ = "media_assets" id: Mapped[int] = mapped_column(Integer, primary_key=True) edition_id: Mapped[int] = mapped_column(ForeignKey("event_editions.id", ondelete="CASCADE"), index=True) file_path: Mapped[str] = mapped_column(String(512)) caption: Mapped[str | None] = mapped_column(String(300), nullable=True) sort_order: Mapped[int] = mapped_column(Integer, default=0) is_published: Mapped[bool] = mapped_column(Boolean, default=True) created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now()) edition: Mapped["EventEdition"] = relationship("EventEdition", back_populates="media")