<?php

namespace App\Http\Controllers\Shop;

use App\Http\Controllers\Controller;
use App\Services\LegalService;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;

class LegalAcknowledgeController extends Controller
{
    public function __invoke(Request $request, LegalService $legalService): RedirectResponse
    {
        $user = $request->user();
        $legal = $legalService->get();

        $user->forceFill([
            'terms_accepted_version' => (int) ($legal['terms_version'] ?? 1),
            'terms_accepted_at' => now(),
        ])->save();

        return back()->with('success', 'Terms acknowledgment recorded.');
    }
}
