<?php

namespace App\Http\Controllers;

use Throwable;

use function Sentry\captureException as gobble;

abstract class HashidControllerBase extends Controller
{
    protected ?int $key = null;

    protected ?string $hashid = null;

    protected function decodeKeys(): void
    {
        $this->hashid = request('hashid');
        $this->decodeHashid($this->hashid);
    }

    protected function decodeHashId(?string $hashid): void
    {
        if (! blank($hashid)) {
            try {
                $this->key = unhash_it($hashid);
            } catch (Throwable $exc) {
                gobble($exc);
            }
        }

        abort_if($this->key === null, 404);
    }
}