package model

import (
	"time"
)

// SecurityLevel 安全等级
type SecurityLevel string

const (
	SecurityLevelSafe   SecurityLevel = "safe"
	SecurityLevelReview SecurityLevel = "review"
	SecurityLevelDanger SecurityLevel = "danger"
)

// Agent 智能体
type Agent struct {
	ID                string   `json:"id" gorm:"primaryKey"`
	Name              string   `json:"name" gorm:"size:100;not null"`
	Description       string   `json:"description" gorm:"type:text"`
	OwnerID           string   `json:"owner_id" gorm:"size:50;not null;index"`

	// Agent能力配置
	Capabilities []string `json:"capabilities" gorm:"type:text"` // JSON数组，可用工具列表
	MemoryLimit  int64    `json:"memory_limit" gorm:"default:134217728"` // 128MB
	Timeout      int      `json:"timeout" gorm:"default:60"` // 60秒

	// 安全配置
	SecurityLevel       SecurityLevel `json:"security_level" gorm:"size:20;default:'safe'"`
	AllowDangerousTools bool          `json:"allow_dangerous_tools" gorm:"default:false"`

	// 扩展字段：角色描述和模型配置
	RoleDescription string `json:"role_description" gorm:"type:text"` // 角色描述 (System Prompt)
	ModelProvider   string `json:"model_provider" gorm:"size:50"`    // 模型提供商: openai/anthropic
	ModelName       string `json:"model_name" gorm:"size:100"`        // 模型名称

	// 协作模式
	IsSupervisor bool `json:"is_supervisor" gorm:"default:false"` // 是否为主智能体

	// 状态
	IsActive bool `json:"is_active" gorm:"default:true"`

	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

// AgentSkill 智能体-技能绑定
type AgentSkill struct {
	ID          string                 `json:"id" gorm:"primaryKey"`
	AgentID     string                 `json:"agent_id" gorm:"size:191;index"`
	SkillID     string                 `json:"skill_id" gorm:"size:191;index"`
	SkillConfig string                 `json:"skill_config" gorm:"type:text"` // JSON 配置
	CreatedAt   time.Time              `json:"created_at"`
	UpdatedAt   time.Time              `json:"updated_at"`
}

// AgentKnowledgeBase 智能体-知识库绑定
type AgentKnowledgeBase struct {
	ID               string    `json:"id" gorm:"primaryKey"`
	AgentID          string    `json:"agent_id" gorm:"size:191;index"`
	KnowledgeBaseID  string    `json:"knowledge_base_id" gorm:"size:191;index"`
	CreatedAt        time.Time `json:"created_at"`
	UpdatedAt        time.Time `json:"updated_at"`
}

// AgentMemory 长期记忆
type AgentMemory struct {
	ID          string    `json:"id" gorm:"primaryKey"`
	AgentID     string    `json:"agent_id" gorm:"size:191;index"`
	UserID      string    `json:"user_id" gorm:"size:191;index"`
	Content     string    `json:"content" gorm:"type:text"`
	MemoryType  string    `json:"memory_type" gorm:"size:20"` // experience/preference/conversation
	Importance  int       `json:"importance" gorm:"default:5"`
	CreatedAt   time.Time `json:"created_at"`
	UpdatedAt   time.Time `json:"updated_at"`
}

// AgentTeam 多智能体协作配置
type AgentTeam struct {
	ID               string    `json:"id" gorm:"primaryKey"`
	SupervisorAgentID string    `json:"supervisor_agent_id" gorm:"size:191;index"`
	MemberAgentID    string    `json:"member_agent_id" gorm:"size:191;index"`
	DispatchStrategy string    `json:"dispatch_strategy" gorm:"size:20;default:'parallel'"`
	CreatedAt        time.Time `json:"created_at"`
	UpdatedAt        time.Time `json:"updated_at"`
}

// AgentTask 任务记录
type AgentTask struct {
	ID            string    `json:"id" gorm:"primaryKey"`
	AgentID       string    `json:"agent_id" gorm:"size:191;index"`
	UserID        string    `json:"user_id" gorm:"size:191;index"`
	UserInput     string    `json:"user_input" gorm:"type:text"`
	AgentResponse string    `json:"agent_response" gorm:"type:text"`
	Status        string    `json:"status" gorm:"size:20"` // pending/running/completed/failed
	TokensUsed    int       `json:"tokens_used" gorm:"default:0"`
	DurationMs    int       `json:"duration_ms"`
	SessionID     string    `json:"session_id" gorm:"size:191;index"`
	CreatedAt     time.Time `json:"created_at"`
	CompletedAt   time.Time `json:"completed_at"`
}

// AgentRequest 聊天请求
type AgentRequest struct {
	AgentID   string                 `json:"agent_id" binding:"required"`
	Message   string                 `json:"message" binding:"required"`
	SessionID string                 `json:"session_id"`
	ModelID   string                 `json:"model_id"`
	Context   map[string]interface{} `json:"context"`
}

// AgentResponse 聊天响应
type AgentResponse struct {
	Reply     string                 `json:"reply"`
	SessionID string                 `json:"session_id"`
	ToolsUsed []string              `json:"tools_used"`
	Metadata  map[string]interface{} `json:"metadata"`
}
