<?php

namespace App\Http\Controllers\Coach;

use App\Http\Controllers\Controller;
use App\Models\Athlete;
use App\Services\Athlete\ProgressChartService;
use Illuminate\View\View;

class ProgressController extends Controller
{
    public function __construct(private readonly ProgressChartService $chartService)
    {
    }

    public function show(Athlete $athlete): View
    {
        $this->authorize('view', $athlete); // AthletePolicy — نیازی به Policy جدید نبود

        $assessments = $athlete->assessments()
            ->with('photos')
            ->orderBy('assessment_date')
            ->get();

        $weightSeries = $this->chartService->series($assessments, 'weight_kg');
        $bmiSeries = $this->chartService->series($assessments, 'bmi');
        $bodyFatSeries = $this->chartService->series($assessments, 'body_fat_percentage');
        $photoPairs = $this->chartService->photoComparisonPairs($assessments);

        return view('coach.progress.show', [
            'athlete' => $athlete,
            'assessments' => $assessments->reverse(),
            'weightSeries' => $weightSeries,
            'bmiSeries' => $bmiSeries,
            'bodyFatSeries' => $bodyFatSeries,
            'photoPairs' => $photoPairs,
        ]);
    }
}
