from datetime import datetime

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

from app.models.base import BaseModel


class UserRefundQuotaLog(BaseModel):
    """Admin audit log for per-user full-refund quota changes."""

    __tablename__ = "user_refund_quota_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_extra: Mapped[int] = mapped_column(Integer, default=0, nullable=False)
    after_extra: Mapped[int] = mapped_column(Integer, default=0, nullable=False)
    before_reset_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True)
    after_reset_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True)
    reason: Mapped[str] = mapped_column(Text, nullable=False)
