package app

import (
	"gorm.io/datatypes"
	"gorm.io/gorm"
)

// AIPreset AI预设配置模型
type AIPreset struct {
	gorm.Model
	UserID      uint   `json:"userId" gorm:"not null;index:idx_preset_user"`
	Name        string `json:"name" gorm:"not null;size:100"`
	Description string `json:"description" gorm:"size:500"`
	IsPublic    bool   `json:"isPublic" gorm:"default:false;index:idx_preset_public"`
	IsDefault   bool   `json:"isDefault" gorm:"default:false"`

	// Sampling Parameters (stored as individual fields for query efficiency)
	Temperature       float64 `json:"temperature" gorm:"default:1.0"`
	TopP              float64 `json:"topP" gorm:"default:1.0"`
	TopK              int     `json:"topK" gorm:"default:0"`
	FrequencyPenalty  float64 `json:"frequencyPenalty" gorm:"default:0"`
	PresencePenalty   float64 `json:"presencePenalty" gorm:"default:0"`
	MaxTokens         int     `json:"maxTokens" gorm:"default:2000"`
	RepetitionPenalty float64 `json:"repetitionPenalty" gorm:"default:1.0"`
	MinP              float64 `json:"minP" gorm:"default:0"`
	TopA              float64 `json:"topA" gorm:"default:0"`

	// Prompt Configuration (stored as JSON for flexibility)
	SystemPrompt  string         `json:"systemPrompt" gorm:"type:text"`
	StopSequences datatypes.JSON `json:"stopSequences" gorm:"type:jsonb"`

	// SillyTavern Extensions (for full compatibility)
	Extensions datatypes.JSON `json:"extensions" gorm:"type:jsonb"`

	// Usage Statistics
	UseCount int `json:"useCount" gorm:"default:0"`

	DeletedAt gorm.DeletedAt `json:"-" gorm:"index"`
}

// TableName 指定表名
func (AIPreset) TableName() string {
	return "ai_presets"
}
