<?php

namespace App\Http\Controllers\Student;

use App\Http\Controllers\Controller;
use App\Http\Requests\Student\UpdateProfileRequest;
use App\Services\UserService;
use Illuminate\Http\Request;
use Inertia\Inertia;
use Inertia\Response; // Added for the return type hint
use Illuminate\Contracts\Auth\MustVerifyEmail; // Added for MustVerifyEmail check

class ProfileController extends Controller
{
    public function __construct(protected UserService $userService) {}

    public function edit(Request $request): Response
    {
        return Inertia::render('Student/Pages/Profile', [
            'mustVerifyEmail' => $request->user() instanceof MustVerifyEmail,
            'status' => session('status'),
            'profile' => $request->user()->customerProfile
        ]);
    }

    public function update(UpdateProfileRequest $request)
    {
        $this->userService->update($request->user(), $request->validated());
        return redirect()->back()->with('success', 'Profile updated successfully.');
    }
}
