<?php

declare(strict_types=1);

namespace App\Http\Controllers\SupportCenter;

use App\Http\Controllers\Controller;
use App\Services\SupportCenter\HostSiteVerificationResponseBuilder;
use App\Services\SupportCenter\HostSiteVerificationStaticPublisher;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

/**
 * 公开 well-known 站点校验 JSON（无需管理端认证）。
 */
final class DberpSiteVerificationJsonController extends Controller
{
    public function __invoke(
        Request $request,
        HostSiteVerificationResponseBuilder $builder,
        HostSiteVerificationStaticPublisher $staticPublisher,
    ): JsonResponse {
        /** @var array<string, mixed> $payload */
        $payload = $builder->build($request);

        $staticPublisher->publishFromPayload($payload);

        return response()->json($payload, 200);
    }
}
