package service

import (
	"x-agents/server/internal/repository"

	"x-agents/server/internal/model"
)

// MemoryService 记忆服务
type MemoryService struct {
	agentRepo *repository.AgentRepository
}

// NewMemoryService 创建记忆服务
func NewMemoryService(agentRepo *repository.AgentRepository) *MemoryService {
	return &MemoryService{
		agentRepo: agentRepo,
	}
}

// CreateMemory 创建记忆
func (s *MemoryService) CreateMemory(agentID, userID, content, memoryType string, importance int) (*model.AgentMemory, error) {
	memory := &model.AgentMemory{
		AgentID:    agentID,
		UserID:     userID,
		Content:    content,
		MemoryType: memoryType,
		Importance: importance,
	}

	err := s.agentRepo.CreateMemory(memory)
	if err != nil {
		return nil, err
	}

	return memory, nil
}

// GetMemories 获取记忆列表
func (s *MemoryService) GetMemories(agentID string, userID string, limit int) ([]model.AgentMemory, error) {
	if userID != "" {
		return s.agentRepo.FindMemoriesByUserID(agentID, userID, limit)
	}
	return s.agentRepo.FindMemoriesByAgentID(agentID, limit)
}

// DeleteMemory 删除记忆
func (s *MemoryService) DeleteMemory(memoryID string) error {
	return s.agentRepo.DeleteMemory(memoryID)
}
