<?php

namespace Modules\PortalApi\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Modules\PortalApi\Support\PortalFixtures;
use Modules\PortalApi\Support\VerifyToken;

class VerifyController extends Controller
{
    /**
     * Public read-only vaccination card.
     * URL: /verify/{petId}?sig=<HMAC>
     * Anyone who scans the QR sees this. No login required.
     */
    public function show(Request $request, int $petId)
    {
        $sig    = $request->query('sig', '');
        $valid  = VerifyToken::verify($petId, $sig);
        $pet    = PortalFixtures::pet($petId);

        return response()->view('portalApi::verify', [
            'pet'      => $pet,
            'valid'    => $valid,
            'sig'      => $sig,
            'clinic'   => 'Happy Paws Clinic',     // TODO: pull from VetPortal settings
            'verifyAt' => now(),
        ], $pet ? 200 : 404);
    }
}
