from datetime import datetime from sqlalchemy import Boolean, DateTime, Integer, Numeric, String, func from sqlalchemy.orm import Mapped, mapped_column, relationship from app.database import Base class Tariff(Base): __tablename__ = "tariffs" id: Mapped[int] = mapped_column(Integer, primary_key=True) name: Mapped[str] = mapped_column(String(64), nullable=False) duration_days: Mapped[int] = mapped_column(Integer, nullable=False) price: Mapped[float] = mapped_column(Numeric(10, 2), nullable=False) currency: Mapped[str] = mapped_column(String(3), default="RUB") max_devices: Mapped[int] = mapped_column(Integer, default=1) traffic_gb: Mapped[int | None] = mapped_column(Integer, nullable=True) is_active: Mapped[bool] = mapped_column(Boolean, default=True) created_at: Mapped[datetime] = mapped_column( DateTime(timezone=True), server_default=func.now() ) updated_at: Mapped[datetime] = mapped_column( DateTime(timezone=True), server_default=func.now(), onupdate=func.now() ) payments: Mapped[list["Payment"]] = relationship( back_populates="tariff", cascade="all, delete-orphan" ) def __repr__(self) -> str: return f""