package models

import "time"

// SenlinAgentAIRateBucket 保存用户在固定窗口内已占用的 AI 请求配额。
// 复合唯一键让单条 UPSERT 在数据库层完成跨进程并发仲裁。
type SenlinAgentAIRateBucket struct {
	ID          uint      `gorm:"primaryKey"`
	UserID      uint      `gorm:"not null;uniqueIndex:uidx_senlin_agent_ai_rate_bucket,priority:1"`
	Action      string    `gorm:"size:100;not null;uniqueIndex:uidx_senlin_agent_ai_rate_bucket,priority:2"`
	WindowStart time.Time `gorm:"not null;uniqueIndex:uidx_senlin_agent_ai_rate_bucket,priority:3"`
	Count       int       `gorm:"not null"`
	CreatedAt   time.Time
	UpdatedAt   time.Time
}

func (SenlinAgentAIRateBucket) TableName() string {
	return "senlin_agent_ai_rate_buckets"
}
