<?php
namespace OxygenApp\Common\Guards;

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

use WP_REST_Request;

class Guards {
    public static function use(WP_REST_Request $request, string ...$guards) {
        
        foreach ($guards as $guard) {
            if (class_exists($guard) && method_exists($guard, 'check')) {
                $result = $guard::check($request);

                if (!$result['status']) {
                    return new \WP_REST_Response([
                        'message' => $result['message']
                    ], $result['code']);
                }
            }
        }
        return true;
    }
}