from sqlalchemy import Boolean, ForeignKey, Integer, String
from sqlalchemy.orm import Mapped, mapped_column, relationship

from app.models.base import Base, TimestampMixin


class TelegramConfig(Base, TimestampMixin):
    """Telegram notification config per SPBU — one row per SPBU."""

    __tablename__ = "telegram_config"

    id: Mapped[int] = mapped_column(primary_key=True)
    spbu_id: Mapped[int] = mapped_column(
        ForeignKey("master_spbu.id", ondelete="CASCADE"), unique=True, index=True, nullable=False
    )
    is_active: Mapped[bool] = mapped_column(Boolean, default=True, nullable=False)

    # ── Group Operasional ──────────────────────────────────────────────────────
    chat_operasional_id: Mapped[str | None] = mapped_column(String(60), nullable=True)
    thread_penjualan_id: Mapped[int | None] = mapped_column(Integer, nullable=True)
    thread_penerimaan_id: Mapped[int | None] = mapped_column(Integer, nullable=True)
    thread_stock_id: Mapped[int | None] = mapped_column(Integer, nullable=True)
    thread_pos_upload_id: Mapped[int | None] = mapped_column(Integer, nullable=True)
    thread_rekonsiliasi_id: Mapped[int | None] = mapped_column(Integer, nullable=True)

    # ── Group Finansial ────────────────────────────────────────────────────────
    chat_finansial_id: Mapped[str | None] = mapped_column(String(60), nullable=True)
    thread_penyetoran_id: Mapped[int | None] = mapped_column(Integer, nullable=True)
    thread_expense_id: Mapped[int | None] = mapped_column(Integer, nullable=True)
    thread_pb_id: Mapped[int | None] = mapped_column(Integer, nullable=True)
    thread_penebusan_id: Mapped[int | None] = mapped_column(Integer, nullable=True)

    # ── Group GA ───────────────────────────────────────────────────────────────
    chat_ga_id: Mapped[str | None] = mapped_column(String(60), nullable=True)
    thread_absensi_id: Mapped[int | None] = mapped_column(Integer, nullable=True)
    thread_housekeeping_id: Mapped[int | None] = mapped_column(Integer, nullable=True)
    thread_sapras_id: Mapped[int | None] = mapped_column(Integer, nullable=True)

    # relationship
    spbu: Mapped["Spbu"] = relationship(foreign_keys=[spbu_id])  # noqa: F821
