from sqlalchemy import BigInteger, ForeignKey, Integer, String, Text
from sqlalchemy.orm import Mapped, mapped_column

from app.models.base import BaseModel


class UserInviteCodeLog(BaseModel):
    """Admin audit log for invite code quota changes."""

    __tablename__ = "user_invite_code_logs"

    user_id: Mapped[int] = mapped_column(
        BigInteger, ForeignKey("users.id", ondelete="CASCADE"), nullable=False, index=True
    )
    operator_id: Mapped[int | None] = mapped_column(BigInteger, nullable=True, index=True)
    action: Mapped[str] = mapped_column(String(24), nullable=False, index=True)
    count: Mapped[int] = mapped_column(Integer, default=0, nullable=False)
    before_used: Mapped[int] = mapped_column(Integer, default=0, nullable=False)
    after_used: Mapped[int] = mapped_column(Integer, default=0, nullable=False)
    before_extra: Mapped[int] = mapped_column(Integer, default=0, nullable=False)
    after_extra: Mapped[int] = mapped_column(Integer, default=0, nullable=False)
    reason: Mapped[str] = mapped_column(Text, nullable=False)
