<?php

namespace Shm\ShmAdmin\AdminRPC;

use Shm\Shm;
use Shm\ShmAdmin\AdminPanel;
use Shm\ShmAdmin\SchemaCollections\ShmExportCollection;
use Shm\ShmAdmin\SchemaCollections\ShmexportsField;
use Shm\ShmAuth\Auth;
use Shm\ShmRPC\ShmRPC;

class AdminRPCListExport
{
    public static function rpc()
    {

        return ShmRPC::lazy(function () {

            return [
                'type' => Shm::arrayOf(ShmExportCollection::structure()),
                'resolve' => function ($root, $args) {

                    Auth::authenticateOrThrow(...AdminPanel::$authStructures);

                    return ShmExportCollection::find([], [
                        'sort' => [ShmexportsField::_ID => -1],
                        'limit' => 10,
                    ]);
                }
            ];
        });
    }
}
