<?php
namespace OxygenApp\Common\Guards;

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

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

class ResetPasswordGuard extends BaseGuard implements GuardInterface {

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

        $fieldsRules = [
            [
                'field_name' => 'code',
                'required' => true,
                'type' => 'string',
                'min_length' => 20,
                'max_length' => 50
            ],
            [
                'field_name' => 'password',
                'required' => true,
                'type' => 'password',
                'min_length' => 7,
            ],
        ];

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

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

        return self::getSuccessResponse();
    }
}