<?php

declare(strict_types=1);

/** APO-249 — GET /api/v1/administration/users */
final class MyronListUsersAction implements MyronAction
{
    public function __construct(private readonly MyronAuthRepository $auth) {}
    public function metadata(): MyronActionMetadata
    {
        return new MyronActionMetadata(
            uri: '/api/v1/administration/users', method: 'GET',
            domain: 'administration', resource: 'user', verb: 'list',
            inputSchema: ['type' => 'object', 'properties' => []],
            outputSchema: ['type' => 'object', 'properties' => ['items' => ['type' => 'array']]],
            requiredScope: MyronApiScopes::ADMINISTRATION_READ,
            summary: 'List operator users with role and granted scopes.',
            audienceClass: 3,
            snapshotInclude: false,
            exposeToMcp: true,
        );
    }
    public function execute(array $input, MyronActionCallerContext $caller): MyronActionResult
    {
        $items = array_map(static function (array $user): array {
            unset($user['password_hash']);
            return $user;
        }, $this->auth->listUsers());
        return MyronActionResult::ok(['items' => $items]);
    }
}
