<?php

namespace HelpGent\App\Http\Controllers;

defined( "ABSPATH" ) || exit;

use HelpGent\App\Http\Controllers\Controller;
use HelpGent\WpMVC\Routing\Response;
use HelpGent\WpMVC\RequestValidator\Validator;
use WP_REST_Request;

use HelpGent\App\Repositories\SettingsRepository;

class SiteVerificationController extends Controller {
    public SettingsRepository $repository;

    public function __construct( SettingsRepository $repository ) {
        $this->repository = $repository;
    }

    /**
     * Verifies the token.
     *
     * @param Validator $validator Instance of the Validator.
     * @param WP_REST_Request $request The REST request instance.
     * @return array
     */
    public function verify_token( Validator $validator, WP_REST_Request $request ): array {
        $validator->validate(
            [
                'token' => 'required|string'
            ]
        );

        helpgent_verify_site_verification_token( $request->get_param( 'token' ) );

        return Response::send(
            [
                "message" => 'The token was verified.'
            ]
        );
    }
}