<?php

namespace App\Http\Controllers;

use App\Models\Trade;
use App\Services\MistakeInsightService;
use Illuminate\Http\Request;
use Illuminate\View\View;

class MistakeTrackerController extends Controller
{
    public function index(Request $request, MistakeInsightService $mistakeInsightService): View
    {
        $trades = Trade::query()
            ->with('mistakeTags')
            ->where('user_id', $request->user()->id)
            ->latest()
            ->paginate(10);

        return view('mistakes.index', [
            'trades' => $trades,
            'insights' => $mistakeInsightService->forUser($request->user()),
        ]);
    }
}
