<?php

namespace App\Services\AI;

use App\Models\User;
use App\Repositories\MoodEntryRepository;
use App\Repositories\ExerciseRepository;

class ContextManager
{
    protected $moodRepo;
    protected $exerciseRepo;

    public function __construct(MoodEntryRepository $moodRepo, ExerciseRepository $exerciseRepo)
    {
        $this->moodRepo = $moodRepo;
        $this->exerciseRepo = $exerciseRepo;
    }

    public function buildContext(User $user): array
    {
        $recentMoods = $this->moodRepo->getUserMoods($user->id, 5);
        $lastExercise = $user->aiConversations()->latest()->first();

        return [
            'user_name' => $user->name,
            'recent_moods' => $recentMoods->pluck('mood_score', 'entry_date')->toArray(),
            'last_ai_interaction' => $lastExercise ? $lastExercise->created_at->diffForHumans() : null,
            'is_premium' => $user->isPremium(),
            'current_time' => now()->toDateTimeString(),
        ];
    }
}
