<?php

namespace App\Http\Controllers\Api\V1;

use App\Http\Controllers\Controller;
use App\Services\Extension\ExtensionVerificationService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class ExtensionController extends Controller
{
    public function __construct(private readonly ExtensionVerificationService $verifier) {}

    public function verify(Request $request): JsonResponse
    {
        $token = trim((string) $request->header('X-Extension-Token', ''));
        $expected = config('dewemoji.public_access.extension_ids', []);
        $ok = $this->verifier->verifyToken($token, is_array($expected) ? $expected : []);

        return response()->json([
            'ok' => $ok,
            'verified' => $ok,
        ], $ok ? 200 : 403);
    }
}
