<?php

declare(strict_types=1);

namespace App\Mcp\Resource;

use Mcp\Capability\Attribute\McpResource;
use Mcp\Schema\Content\TextContent;

#[McpResource(
    uri: 'inventory://roles',
    name: 'Roles & Permissions',
    description: 'Role hierarchy and permissions for MCP tools.',
    mimeType: 'application/json'
)]
class RolesResource
{
    public function __invoke(): array
    {
        $roles = [
            'hierarchy' => [
                'ROLE_ADMIN'        => 'Inherits ROLE_GESTIONNAIRE. Can manage profiles.',
                'ROLE_GESTIONNAIRE' => 'Inherits ROLE_VIEWER. Can create, update, delete all entities.',
                'ROLE_VIEWER'       => 'Inherits ROLE_USER. Can read all entities, create comments, search.',
                'ROLE_USER'         => 'Base role. Authenticated but minimal access.',
            ],
            'tool_permissions' => [
                'ROLE_VIEWER'       => 'list_*, get_*, search_inventory, get_dashboard_stats, get_entity_history, get_activity_log, list_comments, create_comment, get_unresolved_comments_count, list_custom_field_values, list_documents, list_slots',
                'ROLE_GESTIONNAIRE' => 'All VIEWER tools + create_*, update_*, delete_*, clone_machine, update_slots, add_machine_links, remove_machine_link, resolve_comment, upsert_custom_field_values, sync_model_type',
            ],
        ];

        return [new TextContent(text: json_encode($roles, JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE))];
    }
}
