<?php
/**
 * Nemtly REST API abstract class
 *
 * @package NemtlyBooking
 */

namespace NemtlyBooking\API;

abstract class Nemtly_API extends \WP_REST_Controller {
    /**
     * API namespace
     *
     * @var string
     */
    protected $namespace;

    /**
     * Constructor
     *
     * Initializes the API namespace.
     */
    public function __construct() {
        $this->namespace = 'nemtly-booking/v1';
    }

    /**
     * Check if the user has the necessary permissions to access the API
     *
     * @return bool
     */
    public function permission_check() {
        // Check if user is logged in
        if ( ! is_user_logged_in() ) {
            return false;
        }

        // For admin endpoints, require manage_options capability
        // For user endpoints, require edit_posts capability
        $required_capability = apply_filters( 'nemtly_booking_rest_permission_check', 'manage_options' );

        return current_user_can( $required_capability );
    }
}
