"""AI 调用日志 — 用于 5h / 7d 滑动窗口限额"""
from datetime import datetime

from sqlalchemy import BigInteger, DateTime, Index
from sqlalchemy.orm import Mapped, mapped_column

from app.core.models.base import Base


class AiCallLog(Base):
    __tablename__ = "ai_call_logs"
    __table_args__ = (
        Index("ix_ai_call_logs_tenant_called", "tenant_id", "called_at"),
    )

    id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=True)
    tenant_id: Mapped[int] = mapped_column(BigInteger, nullable=False)
    called_at: Mapped[datetime] = mapped_column(
        DateTime, nullable=False, server_default="CURRENT_TIMESTAMP",
    )
