<?php

namespace App\Services\AI;

use App\Models\User;
use App\Repositories\AIConversationRepository;

class MemoryManager
{
    protected $conversationRepo;

    public function __construct(AIConversationRepository $conversationRepo)
    {
        $this->conversationRepo = $conversationRepo;
    }

    public function getRecentMemory(User $user, int $limit = 5): array
    {
        $conversations = $this->conversationRepo->getUserConversations($user->id)
            ->take($limit)
            ->map(function ($conv) {
                return [
                    'user' => $conv->user_message,
                    'assistant' => $conv->assistant_response,
                    'time' => $conv->created_at->toDateTimeString(),
                ];
            })->toArray();

        return $conversations;
    }

    public function store(User $user, string $message, string $response): void
    {
        // already stored
    }
}
