<?php
/**
 * Abstract REST API controller for network-level endpoints.
 *
 * @package NimblyMail\SMTP
 *
 * @since 1.0.0
 */

namespace NimblyMail\SMTP\Rest\Network;

use NimblyMail\SMTP\Rest\AbstractController;

defined( 'ABSPATH' ) || exit;

/**
 * Class AbstractNetworkController
 *
 * Base class for controllers that expose network-level endpoints. Requires
 * the manage_network_options capability and skips route registration on
 * single-site installs where a network layer does not exist.
 *
 * @since 1.0.0
 */
abstract class AbstractNetworkController extends AbstractController {

    /**
     * Check if the current user can manage network options.
     *
     * Overrides the parent site-level check. On single-site installs this
     * capability is not granted so the check naturally fails closed.
     *
     * @since 1.0.0
     *
     * @return bool True if user has manage_network_options capability.
     */
    public function permissions_check(): bool {
        return current_user_can( 'manage_network_options' );
    }

    /**
     * Register routes on this controller.
     *
     * Subclasses implement do_register_routes(). This wrapper guards route
     * registration behind is_multisite() so single-site installs never
     * expose network endpoints at all.
     *
     * @since 1.0.0
     *
     * @return void
     */
    public function register_routes(): void {
        if ( ! is_multisite() ) {
            return;
        }

        $this->do_register_routes();
    }

    /**
     * Subclass-provided route registration.
     *
     * @since 1.0.0
     *
     * @return void
     */
    abstract protected function do_register_routes(): void;
}
