<?php
namespace OxygenApp\Common\Guards;

if ( ! defined( 'ABSPATH' ) ) exit;

use WP_REST_Request;
use OxygenApp\Common\Validation\FieldsValidator;

class ResetPasswordRequestGuard extends BaseGuard implements GuardInterface {

    public static function check(WP_REST_Request $request): array {

        $fieldsRules = [
            [
                'field_name' => 'email',
                'required' => true,
                'type' => 'email',
            ]
        ];

        $params = $request->get_params();
        $validatorResult = FieldsValidator::validate($params, $fieldsRules);

        if (!$validatorResult['status']) {
            return self::getFailedResponse($validatorResult['errorMessage'], 400);
        }

        return self::getSuccessResponse();
    }
}