<?php
/**
 * Route handler for connection status checks.
 *
 * @package    100Prints
 */

class Hundred_Prints_Route_Status {

	/**
	 * Register routes.
	 */
	public function register_routes() {
		register_rest_route( '100prints/v1', '/status', [
			[
				'methods'             => WP_REST_Server::READABLE,
				'callback'            => [ $this, 'get_status' ],
				'permission_callback' => [ $this, 'permission_check' ],
			],
		] );
	}

	/**
	 * Permission check callback.
	 */
	public function permission_check( $request ) {
		return current_user_can( 'manage_options' );
	}

	/**
	 * Get status details.
	 */
	public function get_status( $request ) {
		$conn_service = new Hundred_Prints_Connection_Service();
		$is_connected = $conn_service->is_connected();
		$workspace_info = $conn_service->get_workspace_info();

		return rest_ensure_response( [
			'connected'      => $is_connected,
			'workspace_info' => $workspace_info,
		] );
	}
}
