<?php

namespace App\Http\Controllers;

use Illuminate\Support\Facades\Auth;
use App\Models\Pago;
use App\Models\Compromise;

class EvaluacionCompletadaController extends Controller
{
    public function show($pagoId)
    {
        $user = Auth::user();
        
        // Obtener el pago completado
        $pago = Pago::where('id', $pagoId)
                    ->where('user_id', $user->id)
                    ->where('estado', 'completado')
                    ->firstOrFail();

        // Obtener los compromisos completados
        $compromiso1 = Compromise::where('user_id', $user->id)
                                  ->where('compromise_type', 'compromiso1')
                                  ->where('completed', 1)
                                  ->latest()
                                  ->first();

        $compromiso2 = Compromise::where('user_id', $user->id)
                                  ->where('compromise_type', 'compromiso2')
                                  ->where('completed', 1)
                                  ->latest()
                                  ->first();

        $compromiso3 = Compromise::where('user_id', $user->id)
                                  ->where('compromise_type', 'compromiso3')
                                  ->where('completed', 1)
                                  ->latest()
                                  ->first();

        return view('evaluacion-completada', [
            'pago' => $pago,
            'compromiso1' => $compromiso1,
            'compromiso2' => $compromiso2,
            'compromiso3' => $compromiso3,
        ]);
    }
}
