<?php

declare(strict_types=1);

namespace CliqThemes\StoreLocator\REST;

defined('ABSPATH') || exit;

use CliqThemes\StoreLocator\Support\CategoryIconLibrary;
use WP_REST_Response;

/**
 * The category icon set, read-only.
 *
 * Serves the packaged icons a category can be given. There is nothing to write:
 * the artwork ships with the plugin.
 */
final class CategoryIconsController
{
    public function register(): void
    {
        add_action('rest_api_init', [$this, 'registerRoutes']);
    }

    public function registerRoutes(): void
    {
        register_rest_route(AdminController::NAMESPACE, '/admin/markers/assets', [
            'methods' => 'GET',
            'callback' => [$this, 'assets'],
            'permission_callback' => [$this, 'permission'],
        ]);
    }

    public function permission(): bool
    {
        return current_user_can('manage_store_locator') || current_user_can('manage_options');
    }

    public function assets(): WP_REST_Response
    {
        return new WP_REST_Response(CategoryIconLibrary::assets());
    }
}
